我无法将文件上传到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用于在任何地方上传新文件。
最佳答案
找到了问题。您需要通过“API控制台/服务”标签启用Drive API和Drive SDK。以下是提供帮助的帖子:
Google Drive HTTP 403 "Access Not Configured" error with DrEdit
关于ios - GTMHTTPUploadFetcher connectionDidFinishLoading中的断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18261724/