问题
I have problem with uploading mp4 files to google drive. I am using resumable upload. Chunk size is set as multiplicity of minimal size(depending on file size to be uploaded in order to make progress bar working). Upload of small files is working almost always. But when file is about 50 MB upload fails very often. There is exception EOFException
at the very beginning of upload or exception "Unexpected end of stream
" somewhere in the middle of upload. After many tests it looks that behaviour is random, sometimes working, sometimes not. I am using latest Google Drive API downloaded with eclipse plugin. I am using default authorization with "AccountPicker
" activity. I have seen many hints on google search but nothing has solved the problem. For example setting "System.setProperty("http.keepAlive", "false")
". This is my upload method:
try{
final java.io.File fileContent = new java.io.File(path);
// get MIME type from name:
String mime = getMimeType(fileContent.getAbsolutePath());
FileContent mediaContent = new FileContent(mime, fileContent);
// File's meta-data.
File body = new File();
body.setTitle(fileContent.getName());
body.setMimeType(mime);
// set parent folder:
body.setParents(Arrays.asList(new ParentReference().setId(parentId)));
Files f = mService.files();
Insert i = f.insert(body, mediaContent);
// configure MediaUploader:
MediaHttpUploader uploader = i.getMediaHttpUploader();
uploader.setDirectUploadEnabled(false);
uploader.setProgressListener(new FileUploadProgressListener());
int chunkSize = getDataChunkSize(fileContent.length());
uploader.setChunkSize(chunkSize);
File file = i.execute();
// upload was interrupted
if (Thread.interrupted() == true) {
// file upload was interrupted, currently no action here.
}
else if (file != null) {
// upload finished with success.
}
else if (file == null) {
// upload failed.
}
}
catch (Exception e) {
// upload failed:
}
I noticed that "EOFException
" is generated mainly when google drive is not used for longer time and upload request is done. When for example listing of folders is done and immediately after it upload is done "EOFException
" is not generated. I am creating credential object and drive service object only once per activity time life. Maybe some refresh is needed? Could you please help with this? Thanks in advance.
来源:https://stackoverflow.com/questions/19349405/android-google-drive-resumable-upload-fails-very-often