Note that there are some explanatory texts on larger screens.

plurals
  1. POObjective-C Google Web Albums API - Strange error when trying to upload image
    text
    copied!<p>I'm using the Objective-C version of the API.</p> <p>I've copied the code from the example project almost exactly, but am getting this error every time I try to upload a picture: "failedWithStatus:400 data:Photo data must not be empty.".</p> <p>Here's my code:</p> <pre><code>- (void)uploadToPicasa { // make a new entry for the photo GDataEntryPhoto *newEntry = [GDataEntryPhoto photoEntry]; // set a title, description, and timestamp [newEntry setTitleWithString:@"Title!"]; [newEntry setPhotoDescriptionWithString:@"Description!"]; [newEntry setTimestamp:[GDataPhotoTimestamp timestampWithDate: [NSDate date]]]; // attach the NSData and set the MIME type for the photo UIImage *earth_image = [UIImage imageNamed:@"earth.jpg"]; NSData *earth_data = UIImageJPEGRepresentation(earth_image, 1.0); [newEntry setPhotoData:earth_data]; NSString *mimeType = @"image/jpeg"; [newEntry setPhotoMIMEType:mimeType]; // the slug is just the upload file's filename [newEntry setUploadSlug:@"earth.jpg"]; // make service tickets call back into our upload progress selector GDataServiceGooglePhotos *service = [self googlePhotosService]; SEL progressSel = @selector(ticket:hasDeliveredByteCount:ofTotalByteCount:); [service setServiceUploadProgressSelector:progressSel]; // Get URL for Picasa NSURL *uploadURL = [GDataServiceGooglePhotos photoFeedURLForUserID:@"CORRECT_USERNAME" albumID:nil albumName:nil photoID:nil kind:nil access:nil]; // insert the entry into the album feed GDataServiceTicket *ticket; ticket = [service fetchEntryByInsertingEntry:newEntry forFeedURL:uploadURL delegate:self didFinishSelector:@selector(addPhotoTicket:finishedWithEntry:error:)]; // no need for future tickets to monitor progress [service setServiceUploadProgressSelector:nil]; } // progress callback - (void)ticket:(GDataServiceTicket *)ticket hasDeliveredByteCount:(unsigned long long)numberOfBytesRead ofTotalByteCount:(unsigned long long)dataLength { NSLog([NSString stringWithFormat:@"%d", numberOfBytesRead / dataLength]); } // photo add callback - (void)addPhotoTicket:(GDataServiceTicket *)ticket finishedWithEntry:(GDataEntryPhoto *)photoEntry error:(NSError *)error { if (error == nil) { NSLog(@"SHOULD BE UPLOADED MAYBE"); } else { NSLog(@"THERE WAS AN ERROR"); } } - (GDataServiceGooglePhotos *)googlePhotosService { static GDataServiceGooglePhotos* service = nil; if (!service) { service = [[GDataServiceGooglePhotos alloc] init]; [service setShouldCacheResponseData:YES]; [service setServiceShouldFollowNextLinks:YES]; } // update the username/password each time the service is requested NSString *username = @"CORRECT_USERNAME"; NSString *password = @"CORRECT_PASSWORD"; if ([username length] &amp;&amp; [password length]) { [service setUserCredentialsWithUsername:username password:password]; } else { [service setUserCredentialsWithUsername:nil password:nil]; } return service; } </code></pre> <p>I used a breakpoint to confirm that NSData is not nil, and is the image in question, so I'm not sure what "failedWithStatus:400 data:Photo data must not be empty." could mean. Please help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload