我正在尝试在我的 iOS 应用中使用 Google Drive。我尝试上传文件,我收到以下错误:
*** 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!"];
}
}];
}