7

I want to upload large files (>10Mb) to Google Drive, using the drive api. It is working fine with smaller files (when there's good wifi), using direct upload:

Drive.Files.Insert insert = driveService.files().insert(fileMetadata, mediaContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setChunkSize(UPLOAD_CHUNK_SIZE);
uploader.setDirectUploadEnabled(true);
insert.execute();

Now, suppose we are uploading a larger file. We want to keep track of the connection, so we use resumable upload, given by MediaHttpUploader method...

uploader.setDirectUploadEnabled(false);
uploader.setProgressListener(new MediaHttpUploaderProgressListener() {
    @Override
    public void progressChanged(MediaHttpUploader mediaHttpUploader) throws IOException {
        switch (mediaHttpUploader.getUploadState()) {
            case INITIATION_STARTED:     break;
            case INITIATION_COMPLETE:  break;
            case MEDIA_IN_PROGRESS:   break;
            case MEDIA_COMPLETE:        break;
        }
    }
});

Ok. But there is no state for MEDIA_FAILED, am I correct? And what can I do when the upload does not reach MEDIA_COMPLETE?

Also, I found no method to resume the upload. So even if a 100Mb upload is at 90% and fails, all I can do is start it all over again??

PS: this issue has been reported before without success Check progress for Upload & Download (Google Drive API for Android or Java) Android Google Drive Resumable Upload fails very often

Community
  • 1
  • 1
Ricardo Belchior
  • 576
  • 1
  • 3
  • 14

0 Answers0