google drive sdk上传演示文稿时出错

时间:2012-11-05 22:21:02

标签: java google-app-engine google-drive-api google-docs-api google-api-java-client

我正在尝试上传演示文稿,使用谷歌API驱动器,但演示文稿不完整,一些幻灯片是空白的,看着日志这是显示

com.google.api.client.http.HttpRequest execute: -------------- REQUEST  --------------
PUT https://www.googleapis.com/upload/drive/v2/files?    uploadType=resumable&upload_id=AEnB2UrDPJgLIehcqH--aWgwl-   R_atDhqdvbXnJiWMXKE0V0euJGOvULbM4y5YmvUePWaHSrYyFdOgsmTASJGe-Dtvg09NCkzQ
Accept-Encoding: gzip
Authorization: Bearer ya29.AHES6ZTfSaK77NGCcZO1bK_aTbT8zVX3eslOAb8BkrvpeXARK94XsXY
Content-Range: bytes 0-1048575/6774302
User-Agent: Google-HTTP-Java-Client/1.11.0-beta (gzip)
Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation
Content-Length: 1048576

com.google.api.client.http.HttpRequest execute: curl -v --compressed -X PUT -H 'Accept-        Encoding: gzip' -H 'Authorization: Bearer     ya29.AHES6ZTfSaK77NGCcZO1bK_aTbT8zVX3eslOAb8BkrvpeXARK94XsXY' -H 'Content-Range: bytes 0-    1048575/6774302' -H 'User-Agent: Google-HTTP-Java-Client/1.11.0-beta (gzip)' -H 'Content-Type:     application/vnd.openxmlformats-officedocument.presentationml.presentation' -d '@-' --     https://www.googleapis.com/upload/drive/v2/files?    uploadType=resumable&upload_id=AEnB2UrDPJgLIehcqH--aWgwl-    R_atDhqdvbXnJiWMXKE0V0euJGOvULbM4y5YmvUePWaHSrYyFdOgsmTASJGe-Dtvg09NCkzQ << $$$

com.google.api.client.http.HttpResponse <init>: -------------- RESPONSE --------------
308 OK
server: HTTP Upload Server Built on Oct 3 2012 16:52:30 (1349308350)
range: bytes=0-1048575
x-range-md5: 19230c1c1a0fc493f3431f46cf30c14c
date: Mon, 05 Nov 2012 22:00:33 GMT
pragma: no-cache
expires: Fri, 01 Jan 1990 00:00:00 GMT
cache-control: no-cache, no-store, must-revalidate
content-length: 0
content-type: text/html; charset=UTF-8
x-google-cache-control: remote-fetch
via: HTTP/1.1 GWA

这是我正在使用的代码:

byte[] myFile = readImageData(blobKey,size);
ByteArrayContent mediaContent = new ByteArrayContent(mimeType, myFile);

Drive.Files.Insert insert = service.files().insert(body, mediaContent);
insert.getMediaHttpUploader().setChunkSize(1024 * 1024);
File file = insert.execute();

更新

进行一些测试,似乎只有在上传扩展名为.pptx

的演示文稿时才会出现错误

该扩展名的mimeType有问题吗?

我希望有人可以提前帮助我。

1 个答案:

答案 0 :(得分:0)

似乎resumable upload protocol未正确实施。 308响应代码表示只上传了一大块请求,您应该继续下一个块。

如果从代码中删除以下行,它是否可以正常工作?

insert.getMediaHttpUploader().setChunkSize(1024 * 1024);