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

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

问题描述

我创建该用户的小应用程序可以上传自己的MS Office文件的登记邮件ID G_Drive来自Android设备的帐户。 和出口的文件转换成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/参考/文件/插入#范例

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.

同样的情况下与下载也......

same case with downloading also.....

请给我一些解决方案...这个...

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

推荐答案

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

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

您需要在开始上传之前设置的媒体内容的内容长度。否则,很可能是谷歌端点无法识别上传的被完成,等待直至插槽被超时。

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

其实是有关于<一个完整的基于Android系统的可恢复上传样本href="https://$c$c.google.com/p/google-api-java-client/source/browse/drive-cmdline-sample/src/main/java/com/google/api/services/samples/drive/cmdline/DriveSample.java?repo=samples&r=08555cd2a27be66dc97505e15c60853f47d84b5a"相对=nofollow> [1] 。

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

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