此页面(https://developers.google.com/drive/v2/web/manage-downloads)描述了一种获取下载URL的方法,称为备用方法。这就是我们使用的。我们获取此URL,然后使用此URL发送GET请求。问题是返回的响应没有内容长度,因此我们无法显示进度条。有没有办法强制此URL返回下载内容的内容长度?我们特别感兴趣的是使这个URL返回内容长度,因为我们将URL传递给专门为下载而创建的不同系统,并且该系统没有调用GoogleDrive API的逻辑。以下是响应标头
的示例HTTP/1.1 200 OK
X-GUploader-UploadID: AEnB2UobhZIKOBsST_-cDZt3BvIK2HSQ5ErTDPsA50BdhaAVrF9RD2Py-57pUoRnleNJnd_Xkg2_RoJClvYTzt0kZfaTSdQ61QB3tWXleX1RpefLObvFf2s
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: false
Access-Control-Allow-Headers: Accept, Accept-Language, Authorization, Cache-Control, Content-Disposition, Content-Encoding, Content-Language, Content-Length, Content-MD5, Content-Range, Content-Type, Date, GData-Version, Host, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, Origin, OriginToken, Pragma, Range, Slug, Transfer-Encoding, Want-Digest, X-ClientDetails, X-GData-Client, X-GData-Key, X-Goog-AuthUser, X-Goog-PageId, X-Goog-Encode-Response-If-Executable, X-Goog-Correlation-Id, X-Goog-Request-Info, X-Goog-Experiments, x-goog-iam-authority-selector, x-goog-iam-authorization-token, X-Goog-Spatula, X-Goog-Upload-Command, X-Goog-Upload-Content-Disposition, X-Goog-Upload-Content-Length, X-Goog-Upload-Content-Type, X-Goog-Upload-File-Name, X-Goog-Upload-Offset, X-Goog-Upload-Protocol, X-Goog-Visitor-Id, X-HTTP-Method-Override, X-JavaScript-User-Agent, X-Pan-Versionid, X-Origin, X-Referer, X-Upload-Content-Length, X-Upload-Content-Type, X-Use-HTTP-Status-Code-Override, X-Ios-Bundle-Identifier, X-Android-Package, X-YouTube-VVT, X-YouTube-Page-CL, X-YouTube-Page-Timestamp
Access-Control-Allow-Methods: GET,OPTIONS
Content-Type: application/zip
Content-Disposition: attachment;filename="bluemsx-code-1273.zip";filename*=UTF-8''bluemsx-code-1273.zip
Date: Tue, 04 Oct 2016 00:24:09 GMT
Expires: Tue, 04 Oct 2016 00:24:09 GMT
Cache-Control: private, max-age=0
X-Goog-Hash: crc32c=inH43w==
Transfer-Encoding: chunked
Server: UploadServer
Alt-Svc: quic=":443"; ma=2592000; v="36,35,34,33,32"
答案 0 :(得分:0)
如果您检查Google Drive API中的documentation下载文件,则无法确定文件的内容长度。
因此,基于此SO question的替代方法是,您需要使用下载的XMLHttpRequest
in monitoring the progress。
XMLHttpRequest
提供了侦听处理请求时可能发生的各种事件的功能。这包括定期进度通知,错误通知等。
我找到的另一种方法是tutorial,它使用一个特殊的处理程序来监视名为ProgressListener
的进度。只需查看教程链接以获取更多信息和示例代码。