Domness
Domness

Reputation: 7605

ObjC - Post a UIImage by using NSData and NSURLRequest?

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

Answers (4)

Sherwin
Sherwin

Reputation:

Instead of setPostValue for the image, use setData instead.

Upvotes: 0

pokeb
pokeb

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

Daniel Dickison
Daniel Dickison

Reputation: 21882

Use the UIImagePNGRepresentation function or its JPEG equivalent to turn a UIImage into an NSData:

http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIKitFunctionReference/Reference/reference.html#//apple_ref/c/func/UIImagePNGRepresentation

Upvotes: 2

keremk
keremk

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

Related Questions