【问题标题】:Uploading Downloading of large size file to Google Drive giving error上传大尺寸文件下载到谷歌驱动器给出错误
【发布时间】:2013-04-12 11:40:09
【问题描述】:

我正在从该用户创建一个小型应用程序,可以将他的 MS office 文件从 android 设备上传到他的注册邮件 ID G_Drive 帐户。 并将该文件导出为 PDF 格式。

为此,我采取了以下链接的帮助表格:

https://developers.google.com/drive/v2/reference/files/insert#examples

https://developers.google.com/drive/manage-downloads#downloading_google_documents

我创建了应用程序,它适用于小尺寸(

java.io.exception Unexpected End of Stream
java.net.SocketTimeoutException: Read timed out

我尝试了可恢复上传,但插入方法没有参数来设置它。 如果我将上传类型设置为可恢复

service.files().insert(body, mediaContent).set("upload type", "resumable");

Insert insertService = service.files().insert(body, mediaContent).setConvert(true);
insertService.getMediaHttpUploader().setDirectUploadEnabled(false);         insertService.getMediaHttpUploader().setChunkSize(MediaHttpUploader.DEFAULT_CHUNK_SIZE);
file = insertService.execute();

它也会产生同样的错误。

下载也一样.....

请给我一些解决方案...为此...

【问题讨论】:

    标签: android http google-drive-api


    【解决方案1】:

    不要对大于 5MB 的文件使用基本上传。

    您需要在开始上传之前设置媒体内容的内容长度。否则,Google 端点可能无法识别上传已完成,并一直等到套接字超时。

    InputStreamContent mediaContent = new InputStreamContent("image/jpeg", new   BufferedInputStream(
        new FileInputStream(UPLOAD_FILE)));
    mediaContent.setLength(UPLOAD_FILE.length());
    
    Insert insert = drive.files().insert(fileMetadata, mediaContent);
    MediaHttpUploader uploader = insert.getMediaHttpUploader();
    uploader.setDirectUploadEnabled(false);
    uploader.setProgressListener(new FileUploadProgressListener());
    insert.execute();
    

    [1] 上实际上有一个完整的基于 Android 的可恢复上传示例。

    【讨论】:

    • 我添加了 java.io.File tempFile = new java.io.File(DocxFile); InputStreamContent mediaContent = new InputStreamContent("application/vnd.openxmlformats-officedocument.wordprocessingml.document", new BufferedInputStream(new FileInputStream(tempFile))); mediaContent.setLength(tempFile.length());插入 insert = service.files().insert(body, mediaContent);插入.setConvert(true); insert.getMediaHttpUploader().setDirectUploadEnabled(false); insert.getMediaHttpUploader().setProgressListener(new FileUploadProgressListener());文件=插入.执行();但它对大文件给出错误。
    • 可能有点离题但与此事相关:在这段代码或您提到的示例中,正在处理的“可恢复”部分在哪里?我所看到的只是以块的形式进行插入,但如果一个失败,我们是否必须重新启动它并重新开始?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 2018-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    相关资源
    最近更新 更多