开发者

FTP upload iphone sdk

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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜