Android Google Drive Resumable Upload经常失败

时间:2013-10-13 19:37:44

标签: android upload google-drive-api resume-upload

我将mp4文件上传到Google云端硬盘时遇到问题。我正在使用可恢复的上传。块大小设置为最小大小的多重性(取决于要上载的文件大小以使进度条工作)。几乎总是上传小文件。但是当文件大约50 MB时,上传失败的频率很高。上传或例外情况开始时有例外EOFException" Unexpected end of stream"在上传的某个地方。经过多次测试后,它看起来行为是随机的,有时是有效的,有时则不然。我使用的是使用eclipse插件下载的最新Google Drive API。我正在使用默认授权" AccountPicker"活动。我在谷歌搜索上看到了很多提示,但没有解决问题。例如设置" System.setProperty("http.keepAlive", "false")"。这是我的上传方法:

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:
}

我注意到" EOFException"主要是在谷歌驱动器长时间不使用并且上传请求完成时生成。例如,当文件夹列表完成并且在上传完成后立即完成" EOFException"没有生成。我每个活动时间只创建一次凭证对象和驱动服务对象。也许需要一些刷新?你能帮忙吗?提前谢谢。

0 个答案:

没有答案
相关问题