错误500 - 获取下载drive.files.export

时间:2017-03-31 15:35:29

标签: ios objective-c google-drive-api

我遇到了大小超过5 MB(可能是?)的谷歌驱动器文件的问题。我正在尝试下载它们并将它们导出为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.对于小于5 MB的文件,它正确地执行它我能够取回pdf文件。这通常在30秒内完成,这也意味着它不是身份验证问题。

我也尝试将mimeType更改为vnd.openxmlformats-officedocument.wordprocessingml.document,我会收到403错误"message": "This file is too large to be exported."

知道如何解决这个问题吗?

谢谢。

1 个答案:

答案 0 :(得分:0)

500错误通常是内部Drive基础架构内超时的结果。这与您所看到的症状相符。因此,一个大文件需要花费很长时间才能呈现到.pdf,基础设施正在超时。

标准建议是应使用指数退避算法退回和重试500个错误。在你的情况下,我建议在5秒开始退避,一旦你退出并重试总共30秒,如果它仍然失败你应该放弃。