Ravindhiran
Ravindhiran

Reputation: 5384

how to upload an image on google drive(error "Assertion failure in GTMHTTPUploadFetcher connectionDidFinishLoading")

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

Answers (1)

Ravindhiran
Ravindhiran

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".

enter image description here

You need to enable Drive API and Drive SDK from the API Console/Services tab

Upvotes: 1

Related Questions