我正在尝试在我的 iOS 应用程序中使用 Google 云端硬盘。我尝试上传文件,但出现以下错误:
*** Assertion failure in -[GTMHTTPUploadFetcher connectionDidFinishLoading:],
/Users/mac/Desktop/google-api-objectivec-client-mirror-master/Source/HTTPFetcher/GTMHTTPUploadFetcher.m:399
这是断言发生时突出显示的代码:
NSAssert([[self downloadedData] length] == 0,
@"unexpected response data (uploading to the wrong URL?)");
上传图片到谷歌驱动器:
- (void)uploadPhoto
{
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"'Quickstart Uploaded File ('EEEE MMMM d, YYYY h:mm a, zzz')"];
GTLDriveFile *file = [GTLDriveFile object];
file.title = [dateFormat stringFromDate:[NSDate date]];
file.descriptionProperty = @"Uploaded from the Google Drive iOS Quickstart";
file.mimeType = @"image/png";
UIImage *img =[UIImage imageNamed:@"Default.png"];
NSData *data = UIImagePNGRepresentation(img);
GTLUploadParameters *uploadParameters = [GTLUploadParameters uploadParametersWithData:data MIMEType:file.mimeType];
GTLQueryDrive *query = [GTLQueryDrive queryForFilesInsertWithObject:file
uploadParameters:uploadParameters];
UIAlertView *waitIndicator = [self showWaitIndicator:@"Uploading to Google Drive"];
[self.driveService executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,GTLDriveFile *insertedFile, NSError *error)
{
[waitIndicator dismissWithClickedButtonIndex:0 animated:YES];
if (error == nil)
{
NSLog(@"File ID: %@", insertedFile.identifier);
[self showAlert:@"Google Drive" message:@"File saved!"];
}
else
{
NSLog(@"An error occurred: %@", error);
[self showAlert:@"Google Drive" message:@"Sorry, an error occurred!"];
}
}];
}
最佳答案
试试这个,
我纠正了 GTMHTTPUploadFetcher connectionDidFinishLoading 中的断言失败”)错误,不幸的是我忘记启用 Google API Console驱动 API
1.创建应用。
2.转到“服务”,打开“Drive API”。
您需要从 API 控制台/服务选项卡启用 Drive API 和 Drive SDK
关于iphone - 如何在谷歌驱动器上上传图片(错误 "Assertion failure in GTMHTTPUploadFetcher connectionDidFinishLoading"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18288487/