ObjectiveFlickr photo upload error
I am working on using the ObjectiveFlickr library to upload photos to Flickr from my iPhone app. I can authorize the application and perform general requests, but when I try to upload a photo, I get an error. The photo to be uploaded is an image captured using AVFoundation. Here's the relevant code:
UIImage *image = [[UIImage alloc] initWithData:imageData];
if ([[AppDelegate sharedDelegate].apiContext.OAuthToken length]) {
NSData *uploadData = UIImageJPEGRepresentation(image, 1);
if (!flickrRequest) {
flickrRequest = [[OFFlickrAPIRequest alloc] initWithAPIContext:[AppDelegate sharedDelegate].apiContext];
flickrRequest.delegate = self;
flickrRequest.requestTimeoutInterval = 60.0;
}
[flickrRequest uploadImageStream:[NSInputStream inputStreamWithData:uploadData] suggestedFilename:@"Test" MIMEType:@"image/jpeg" arguments:[NSDictionary dictionaryWithObjectsAndKeys:@"0", @"is_public", nil]];
[UIApplication sharedApplication].idleTimerDisabled = YES;
NSLog(@"Can upload photo");
The object is flickrRequest
defined and @property
'd' in the .h file related to the above code.
The methods OFFlickrRequestDelegate
look like this:
- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest imageUploadSentBytes:(NSUInteger)inSentBytes totalBytes:(NSUInteger)inTotalBytes {
NSLog(@"Success");
}
- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didCompleteWithResponse:(NSDictionary *)inResponseDictionary {
NSLog(@"%s %@ %@", __PRETTY_FUNCTION__, inRequest.sessionInfo, inResponseDictionary);
}
- (void)flickrAPIRequest:(OFFlickrAPIRequest *)inRequest didFailWithError:(NSError *)inError {
NSLog(@"%s %@ %@", __PRETTY_FUNCTION__, inRequest.sessionInfo, inError);
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[inError description] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
When I run the project on the device, the console shows:
Can upload photo
Success
Success
Success
Success
flickrAPIRequest:didFailWithError:(null) Error Domain=org.lukhnos.ObjectiveFlickr Code=2147418115 "The operation couldnโรรดt be completed. (org.lukhnos.ObjectiveFlickr error 2147418115.)"
Search API documentation "error 2147418115
" is defined as " OFFlickrAPIRequestFaultyXMLResponseError
". I'm not really sure what that means. Also strange - "Success" appears four times when I only try to upload one photo.
A sample application using ObjectiveFlickr, "Snap and Run," uploads photos on the same device I'm testing on. Comparing the code between my app and Snap and Run, I don't see any major differences that could cause the photo to not upload.
Any help would be greatly appreciated.
source to share
This is strange. OFFlickrAPIRequestFaultyXMLResponseError
means the returned data cannot be parsed as XML. If the sample SnapAndRun app is working correctly and yours is not, I suggest adding one line to ObjectiveFlickr.m right after the line NSString *stat = [rsp objectForKey:@"stat"];
:
NSString *dataString = [[[NSString alloc] initWithData:[request receivedData] encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"received response: %@", dataString);
This can help you figure out what went wrong (for example, if it is a server side issue or some response format that the library missed).
source to share
When I got this error, I used Charles to see what was going on. Flickr posted an error stating that the signature was invalid. Looking at my request, I found that I had changed the order of the key and value (i.e. there was a space in one of my keys, which probably caused a signature error).
source to share