Reputation: 7605
I'm trying to post an image to TwitPic.com using their API.
However, I have never posted an image using HTTPPOST or however else before.
Anybody enlighten me to how I can post NSData from a UIImage using their api?
Upvotes: 0
Views: 5305
Reputation: 786
@Jamie:
Try:
[request setData:twitpicImage forKey:@"media"];
If the image view is actually displaying an image that is stored in a file on disk, use:
[request setFile:theImagePath forKey:@"media"];
This way, ASIHTTPRequest will stream the image data from disk, so you don't have to keep an NSData instance in memory.
Ta
Ben
Upvotes: 1
Reputation: 21882
Use the UIImagePNGRepresentation
function or its JPEG equivalent to turn a UIImage into an NSData:
Upvotes: 2
Reputation: 2303
TwitPic is expecting a multi-part form data. There is a great open source library called ASIHTTPRequest.
You can use their APIs and post your image as multi-part/form-data.
See below for the sample.
http://allseeing-i.com/ASIHTTPRequest/How-to-use
Upvotes: 5