2

我在将文件上传到 Google 云端硬盘时遇到问题。我仔细按照说明进行操作,并且能够登录并验证用户身份,但是当我上传文件时,我遇到了以下断言:

*断言失败 -[GTMHTTPUploadFetcher connectionDidFinishLoading:], /Users/.../google-api-objectivec-client-read-only/Source/HTTPFetcher/GTMHTTPUploadFetcher.m:399

我仔细检查并确保 -ObjC -all_load 在其他链接器标志中。

这是我正在使用的代码,它基本上只是 Google 在他们的示例中使用的代码的副本。

NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *localPath = [paths objectAtIndex:0];
NSString *filePath = [NSString stringWithFormat:@"%@/%@",
                      localPath,fileNameString];

NSData *myFileData = [NSData dataWithContentsOfFile:filePath];

GTLDriveFile *file = [GTLDriveFile object];
file.title = fileNameString;
file.descriptionProperty = fileNameString;
file.mimeType = @"application/pdf";

GTLUploadParameters *uploadParameters = [GTLUploadParameters
                                         uploadParametersWithData:myFileData
                                         MIMEType:@"application/pdf"];

GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:file
                                                   uploadParameters:uploadParameters];

[self.driveService executeQuery:query
              completionHandler:^(GTLServiceTicket *ticket,
                                  GTLDriveFile *updatedFile,
                                  NSError *error) {
                  if (error == nil) {
                      NSLog(@"file uploaded");
                  } else {
                      NSLog(@"upload failed");            
                  }
              }];

以下是断言发生时突出显示的代码:

  // The initial response of the resumable upload protocol should have an
  // empty body
  //
  // This assert typically happens because the upload create/edit link URL was
  // not supplied with the request, and the server is thus expecting a non-
  // resumable request/response.
  NSAssert([[self downloadedData] length] == 0,
                    @"unexpected response data (uploading to the wrong URL?)");

有谁知道他们指的是什么网址?我还没有看到用于在任何地方上传新文件的 URL。

4

1 回答 1

0

发现了问题。您需要从 API 控制台/服务选项卡启用 Drive API 和 Drive SDK。这是帮助的帖子:

DrEdit 的 Google Drive HTTP 403“未配置访问”错误

于 2013-08-19T16:45:44.770 回答