2

我正在尝试使用我设置的最低google-api-services-drive版本将大文件插入谷歌的驱动器,以便更频繁地通知我自己。以下代码用于插入文件:v2-rev93-1.16.0-rcsetChunkSize()ProgressListener

File body = new File();
body.setTitle(filetobeuploaded.getName());
body.setMimeType("application/zip");
body.setFileSize(filetobeuploaded.length());

InputStreamContent mediaContent =
        new InputStreamContent("application/zip",
        new BufferedInputStream(new FileInputStream(filetobeuploaded)));
mediaContent.setLength(filetobeuploaded.length());

Insert insert = drive.files().insert(body, mediaContent);
MediaHttpUploader uploader = insert.getMediaHttpUploader();
uploader.setChunkSize(MediaHttpUploader.MINIMUM_CHUNK_SIZE);
uploader.setProgressListener(new CustomProgressListener(filetobeuploaded));
insert.execute();

在“一段时间”之后(有时 200 MB 有时 300 MB)我得到了IOException

Exception in thread "main" java.io.IOException: insufficient data written
at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.close(HttpURLConnection.java:3213)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:81)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:960)
at com.google.api.client.googleapis.media.MediaHttpUploader.executeCurrentRequest(MediaHttpUploader.java:482)
at com.google.api.client.googleapis.media.MediaHttpUploader.upload(MediaHttpUploader.java:390)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:418)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:343)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:460)

任何想法如何让这段代码工作?

4

4 回答 4

0

“一段时间”是否恰好意味着 1 小时?在这种情况下,您可能会遇到以下错误:

http://code.google.com/p/gdata-issues/issues/detail?id=5124

于 2013-09-09T22:59:46.887 回答
0

由于时间限制,您将无法从前端运行它。唯一可靠的方法(但很痛苦)是使用可恢复上传从后端执行此操作,因为在处理块时也可能关闭后端/任务队列。

于 2013-08-25T00:17:15.397 回答
0

此问题仅适用于 Drive Resumable Media 上传。检查这个回复.. https://stackoverflow.com/a/30796105/4576135

于 2015-06-12T06:04:49.033 回答
0

对我来说,这意味着“您正在执行 POST 并指定了内容长度,但是您上传的流不够长,无法匹配该内容长度”(在我的情况下,一个封闭的 bytearray 流已关闭,因为以前基本上习惯于“已经筋疲力尽了”,事实上)。

于 2015-08-19T23:21:40.183 回答