我想使用驱动器api将大文件(> 10Mb)上传到Google云端硬盘。它适用于较小的文件(当有良好的wifi时),使用直接上传:
Drive.Files.Insert insert = driveService.files().insert(fileMetadata, mediaContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setChunkSize(UPLOAD_CHUNK_SIZE);
uploader.setDirectUploadEnabled(true);
insert.execute();
现在,假设我们正在上传更大的文件。我们希望跟踪连接,因此我们使用MediaHttpUploader方法提供的可恢复上传...
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;
}
}
});
确定。但是没有 MEDIA_FAILED 的状态,我是否正确?如果上传未达到 MEDIA_COMPLETE ,我该怎么办?
另外,我找不到恢复上传的方法。所以,即使100Mb的上传量达到90%并且失败了,我所能做的就是重新开始它?
PS:此问题之前已报告未成功 Check progress for Upload & Download (Google Drive API for Android or Java) Android Google Drive Resumable Upload fails very often