将文件插入Google云端硬盘时发生IOException [英] IOException when insert file to Google Drive

查看:197
本文介绍了将文件插入Google云端硬盘时发生IOException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


$ b

  java.io.IOException:数据写入不足
at sun.net.www.protocol.http.HttpURLConnection $ StreamingOutputStream.close(HttpURLConnection.java:2822)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest。 java:83)
,位于com.google.api.client.http.HttpRequest.execute(HttpRequest.java:895)
位于com.google.api.client.googleapis.media.MediaHttpUploader.upload( MediaHttpUploader.java:280)
,位于com.google.api.services.drive.Drive $ Files $ Insert $执行解压缩(Drive.java:309)
,位于com.google.api.services.drive。 Drive $ Files $ Insert.execute(Drive.java:331)

我相信它与此相关: http://code.google.com/p / google-api-java-client / issues / detail?id = 521



有没有办法绕过这个?我想知道是否可以插入一个文件,而不使用从谷歌驱动器sdk的可恢复的上传API? 解决方案

我相信我回答我自己的问题,如何做一个直接上传:

  Insert insert = this.driveClient.files()。insert(body ,mediaContent); 
insert.getMediaHttpUploader()。setDirectUploadEnabled(true);
文件结果= insert.execute();

然而,仍然不确定数据写入错误的原因。


I am encountering the following issue when posting an image to google drive:

java.io.IOException: insufficient data written
at sun.net.www.protocol.http.HttpURLConnection$StreamingOutputStream.close(HttpURLConnection.java:2822)
at com.google.api.client.http.javanet.NetHttpRequest.execute(NetHttpRequest.java:83)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:895)
at com.google.api.client.googleapis.media.MediaHttpUploader.upload(MediaHttpUploader.java:280)
at com.google.api.services.drive.Drive$Files$Insert.executeUnparsed(Drive.java:309)
at com.google.api.services.drive.Drive$Files$Insert.execute(Drive.java:331)

I believe its related to this: http://code.google.com/p/google-api-java-client/issues/detail?id=521

Is there a way to circumvent this? I was wondering if possible to insert a file without using the resumable upload api from the google drive sdk?

解决方案

I believe i answered my own question as to how to do a direct upload:

Insert insert = this.driveClient.files().insert(body, mediaContent);
insert.getMediaHttpUploader().setDirectUploadEnabled(true);
File result = insert.execute();

However, still not sure of the cause of the insufficient data written error.

这篇关于将文件插入Google云端硬盘时发生IOException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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