I need to upload
a single file. I have tried ASIRequest
or whatever it is called, but would like to have something with a detailed guide.
Asked
Active
Viewed 1,248 times
0

Girish
- 4,692
- 4
- 35
- 55

Michael Amici
- 308
- 1
- 4
- 18
-
possible duplicate of [How to connect with FTP server?](http://stackoverflow.com/questions/1998122/how-to-connect-with-ftp-server) – Brad Larson Aug 03 '10 at 15:24
1 Answers
0
You'll want to use ASIFormDataRequest. You'll send your file as an NSData object in the request. Here's an example of sending a JPEG. If you have some other file type, you'll need to convert it to an NSData object for transmission to the server.
NSString *filename = @"image.jpg";
UIImage *image = [UIImage imageNamed:@"image.jpg"];
NSData *fileData = UIImageJPEGRepresentation(image, 0.9);
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL urlWithString:@"http://www.yoursite.com"]];
[request setPostValue:filename forKey:@"name"];
[request setData:fileData forKey:@"file"];
[request setTimeOutSeconds:500];
[request setRequestMethod:@"POST"];
[request startSynchronous];
// handle response from server
The ASI docs go over this in the section titled "Sending a form POST with ASIFormDataRequest" - http://allseeing-i.com/ASIHTTPRequest/How-to-use

Steve Goodman
- 1,196
- 10
- 22