我正在尝试使用Google 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有什么问题吗?

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

最佳答案

看来resumable upload protocol的实现不正确。 308响应代码表示只有一部分请求已上载,您应该继续下一个块。

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

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

10-07 17:34