我遇到了一个google驱动器文件大于5MB的问题(也许?)在尺寸上。我试图下载它们并将它们导出为application/pdf,但遇到了错误500。
我使用以下代码来检索和下载驱动器文件(doc、ppt或xls):
- (void)downloadFile:(NSString *)fileID
completionBlock:(void (^)(NSString *))onCompletionBlock
failBlock:(void (^)(NSError *))onDownloadFailBlock {
GTLRQuery *query = [GTLRDriveQuery_FilesExport queryForMediaWithFileId:fileID mimeType:@"application/pdf"];
GTLRDriveService *service = self.driveService;
[service executeQuery:query
completionHandler:^(GTLRServiceTicket *callbackTicket,
GTLRDataObject *dataObject,
NSError *callbackError) {
if (callbackError == nil) {
// The file downloaded successfully; its data is available as dataObject.data
// File has been downloaded
} else {
if (onDownloadFailBlock) {
onDownloadFailBlock(callbackError);
}
return;
}
}];
}下面是我使用GTMSessionFetcher获得的日志
Download drive.files.export
2017-03-30 22:37:50 +0000 elapsed: 29.406sec
Request: GET https://www.googleapis.com/drive/v3/files/[fileID]/export?alt=media&mimeType=application%2Fpdf
Request headers:
Accept: application/json
Authorization: Bearer _snip_
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
User-Agent: org.cocoapods.GoogleAPIClientForREST/1.2.1 google-api-objc-client/3.0 iPhone/10.2 hw/sim (gzip)
Response: status 500
Response headers:
Cache-Control: private, max-age=0
Content-Encoding: gzip
Content-Length: 123
Content-Type: application/json; charset=UTF-8
Date: Thu, 30 Mar 2017 22:37:50 GMT
Expires: Thu, 30 Mar 2017 22:37:50 GMT
Server: GSE
Vary: Origin, X-Origin
alt-svc: quic=":443"; ma=2592000; v="37,36,35"
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
Response body: (180 bytes)
{
"error" : {
"message" : "Internal Error",
"errors" : [
{
"reason" : "internalError",
"message" : "Internal Error",
"domain" : "global"
}
],
"code" : 500
}
}对于它的价值,它似乎有一个服务器限制30秒,当它将抛出这个错误- 500。对于小于5MB的文件,它正在正确地执行,并且我能够取回pdf文件。这通常在30秒内完成,而且这也意味着这不是身份验证问题。
我还尝试将mimeType更改为vnd.openxmlformats-officedocument.wordprocessingml.document,得到一个403错误,显示为"message": "This file is too large to be exported."。
你知道怎么解决这个问题吗?
谢谢。
发布于 2017-04-01 02:54:26
500错误通常是内部驱动器基础架构中超时的结果。这与你所看到的症状是一致的。因此,将一个大文件渲染到.pdf需要花费很长时间,导致基础架构超时。
标准建议是500个错误应该回退,并使用指数回退算法重试。在你的情况下,我建议在5s开始回退,一旦你已经回退并重试了总共30秒,如果它仍然失败,你应该放弃。
https://stackoverflow.com/questions/43144576
复制相似问题