上传大尺寸文件下载到谷歌驱动器给出错误 [英] Uploading Downloading of large size file to Google Drive giving error

查看:12
本文介绍了上传大尺寸文件下载到谷歌驱动器给出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am Creating a small Apps from that user can upload his MS office file to his registered mail ID G_Drive account from android device. and export that file into PDF Format.

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

for that i taken help form below link :

https://developers.google.com/drive/v2/参考/文件/插入#examples

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

我创建了应用程序,它适用于小尺寸(<1MB)文件,但是当我向 g_Drive 发送大尺寸文件时,我收到以下错误:

i created application, and its working fine for small size(< 1MB) file, but when i am sending large size to the g_Drive than i am getting below errors:

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

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

i tried for Resumable upload, but the insert method doesn't have parameter to set this. if am setting the upload type to resumable with

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();

它也会产生同样的错误.

than also its generating same errors.

下载也一样.....

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

please send me some solutions...for this...

推荐答案

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

Don't use basic upload for files larger than 5MB.

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

You need to set the content length of the media content before starting to upload. Otherwise, it's likely that Google endpoint can't recognize the upload's being finished and it waits until the socket is being timed out.

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].

这篇关于上传大尺寸文件下载到谷歌驱动器给出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆