tags:

views:

19

answers:

1

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.

A: 

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