No Name
No Name

Reputation: 1543

How to upload a file to the server in iPhone SDK?

I want to send a file to server in iPhone. Is there any iPhone API to implement that functionality?

Upvotes: 3

Views: 4659

Answers (2)

shinynewbike
shinynewbike

Reputation: 2352

ASIHTTPRequest is a wrapper around the network APIs and makes it very easy to upload a file. Here's their example (but you can do this on the iPhone too - save images to "disk" and later upload them.

ASIFormDataRequest *request = [[[ASIFormDataRequest alloc] initWithURL:url] autorelease];
[request setPostValue:@"Ben" forKey:@"first_name"];
[request setPostValue:@"Copsey" forKey:@"last_name"];
[request setFile:@"/Users/ben/Desktop/ben.jpg" forKey:@"photo"];

Upvotes: 5

Related Questions