Reputation: 5384
I'm trying to use Google Drive in my iOS app. I try to upload a file, I get the following error:
*** Assertion failure in -[GTMHTTPUploadFetcher connectionDidFinishLoading:],
/Users/mac/Desktop/google-api-objectivec-client-mirror-master/Source/HTTPFetcher/GTMHTTPUploadFetcher.m:399
Here is the code that is highlighted when the assertion occurs:
NSAssert([[self downloadedData] length] == 0,
@"unexpected response data (uploading to the wrong URL?)");
upload image to google drive:
- (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!"];
}
}];
}
Upvotes: 1
Views: 841
Reputation: 5384
Try this,
I rectified Assertion failure in GTMHTTPUploadFetcher connectionDidFinishLoading”) error unfortunately i forget to enable Google API Console Drive API
1.Create an App.
2.Go to Services, switch ON the "Drive API".
You need to enable Drive API and Drive SDK from the API Console/Services tab
Upvotes: 1