Reputation: 7389
Hey i have a mac application with the following code:
NSURL *url;
url = [NSURL URLWithString:@"http://yfrog.com/api/xauth_upload"];
ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setDelegate:self];
[request setUseCookiePersistence:NO];
[request setUploadProgressDelegate:self];
[request showAccurateProgress];
[request signRequestWithClientIdentifier:@"w" secret:@"x" tokenIdentifier:@"y" secret:@"z" usingMethod:ASIOAuthHMAC_SHA1SignatureMethod];
[request setPostValue:@"a" forKey:@"key"];
NSData *imageData = [[NSData alloc]initWithContentsOfFile:[draggedFilenames objectAtIndex:0]];
[request setPostValue:imageData forKey:@"media"];
[request startAsynchronous];
But the problem is i always get this response from yfrog servers:
So something is wrong with the image upload. On iPhone it works like this:
[request setData:UIImageJPEGRepresentation(picture, 0.8) withFileName:@"filename.jpg" andContentType:@"image/jpeg" forKey:@"media"];
But this doesn't work cocoa(mac) because there is no method like UIIMageJPEGRepresentation. Also the authentication works, this cant be the problem. If you ask you about this method signRequestWithClientIdentifier it is from the asihttprequest+oauth wrapper from here: https://github.com/keybuk/asi-http-request-oauth
So how can i upload the image correctly ?
Thanks so much.
Upvotes: 0
Views: 641
Reputation: 4296
NSData* NSImageJPEGRepresentation(NSImage* image, CGFloat compressionQuality)
{
if(nil == image)return nil;
NSDictionary *dict;
dict = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithFloat:compressionQuality],
NSImageCompressionFactor,
nil];
NSBitmapImageRep* imageRep;
imageRep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
return [imageRep representationUsingType:NSJPEGFileType
properties:dict];
}
Upvotes: 2