I have an Android application which upload a zipped backup of your files in the Cloud.
Until recently I was using exclusively Dropbox and it was working very well.
Recently I decided to implement the support for Google Drive.
When the file is small (approx 15Mb), it is working... most of the time (sometimes I get a 401 error after the upload has started).
When the file is big (>1Gb), I always get the error :
java.io.IOException: unexpected end of stream
Here is my code:
public CloudResult sendFile(File fileContent, long added) {
CloudResult result = new CloudResult();
try {
mProgress = new FileUploadProgressListener(fileContent.getName());
mediaContent = new FileContent(ZIP_MIME_TYPE, fileContent);
com.google.api.services.drive.model.File body = new com.google.api.services.drive.model.File();
body.setTitle(fileContent.getName());
body.setMimeType(ZIP_MIME_TYPE);
Drive.Files.Insert inserted = getDrive().files().insert(body, mediaContent);
inserted.getMediaHttpUploader()
.setDirectUploadEnabled(false)
.setChunkSize(MediaHttpUploader.DEFAULT_CHUNK_SIZE)
.setProgressListener(mProgress);
com.google.api.services.drive.model.File f = inserted.execute();
// loop over all files in drive and see if any need to be
// synced locally
FileList driveFilesList = getDrive().files().list().execute();
mTotalUploaded = added;
for (com.google.api.services.drive.model.File remote : driveFilesList.getItems()) {
Log.d(Ln.TAG, remote.getLabels().toPrettyString());
}
} catch (IOException e) {
result = new CloudResult(getClass().getSimpleName() + " - " + e.getLocalizedMessage());
if (Ln.DEBUG) {
Log.e(Ln.TAG, "Error in GDrive - " + e.getLocalizedMessage(), e);
}
}
return result;
}
As I don't have real controlon the InputStream, I don't know what to do.
I have already some waker on during the process.
Everything is executed in a thread inside a Service. The Service is the same than for Dropbox, so the error is not about the way this code is executed. It is somewhere else, but I don't know where! May be a bug with GDrive.
I have found these threads, but there is no real answer: Uploading jpeg to Google Drive from Android app "unexpected end of stream"
Any ideas?
Second question: how to get a linear progress listener and not something which is called after each chunck is uploaded (here every 10Mb)?