Kinvey Android SDK - File Uploading - SocketTimeoutException: Read timed out

628 views Asked by At

I'm trying to upload a file from my android device to the Kinvey File Storage, but I get:

java.net.SocketTimeoutException: Read timed out.

I do see the file uploaded on the Kinvey Console, but it's corrupted and the file size when I try to download is 10mb, where as the original file size is ~50mb. The code is as follows (pretty close to the documentation):

File file = new File(Environment.getExternalStorageDirectory(), "images.zip");

FileMetaData metadata = new FileMetaData();  //create the FileMetaData object
metadata.setId("images");
metadata.setFileName("images.zip");
AccessControlList acl = new AccessControlList();
acl.setGloballyReadable(true);
metadata.setAcl(acl);

mKinveyClient.file().upload(metadata, file, new UploaderProgressListener() {

    @Override
    public void onSuccess(Void arg0) {
        // TODO Auto-generated method stub

    }

    @Override
    public void onFailure(Throwable arg0) {
        // TODO Auto-generated method stub
    }

    @Override
    public void progressChanged(MediaHttpUploader uploader) throws IOException {
    }
});

I have posted the same question here (Kinvey Support Forums).

Update

Following ewilly's answer I did some tests.

  • Uploaded a file ~9mb. Works fine. Can download and extract file is not corrupted. Correct file size is displayed.
  • Uploaded a file ~19mb, uploads without socketTimeoutException. But The uploaded file is corrupt. When downloading shows the file size as 10mb.
  • Previous case still stands for file size ~ 50mb.
2

There are 2 answers

3
ewilly On

I read the FAQ of the kinvey website. This may helps you:

I think youre file is too large. the kinvey API only allow files under 20MB to be imported, In your case, you can split the file into chunks or create a script to import using the REST API.

1
edthethird On

have you attempted to retry the file upload after a failure is caught?

note that 50mb is a rather large file, so you might also want to ensure the device is on wifi. If you are using a data plan, and the connection cuts out unfortunately there isn't much that can be done about it.