开发者

having trouble upload image from iphone Photo Picker to a server using ASIFormDataRequest

Basically I am trying to upload an image using ASIFormDataRequest. This is my following code

ASIFormDataRequest *request = [ASIHTTPRequest requestWithURL:urlImg];
[request setRequestMethod:@"POST"];
[request addRequestHeader:@"Content-Type" value:@"application/xml"];
[request setDelegate:self];

[request setTimeOutSeconds:500];  
NSData *imageData = UIImagePNGRepresentation([info objectForKey:@"UIImagePickerControllerOriginalImage"]);
[request setData:imageData forKey:@"media"];
[request startAsynchronous];

Basically my app wold crash and give me the following error:

[ASIHTTPRequest setData:forKey:]: unrecognized selector sent to instance 0x8880db0
2010-06-28 12:33:49.803 vdq[7658:207] *** Ter开发者_如何转开发minating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[ASIHTTPRequest setData:forKey:]: unrecognized selector sent to instance 0x8880db0'

Not sure why, but the method setData seems to be in that instance.


Couple of things. The reason you are getting that is because of the first line:

ASIFormDataRequest *request = [ASIHTTPRequest requestWithURL:urlImg];

is creating a new object of the type ASIHTTPRequest. You need to do:

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:urlImg];

Also, you don't need to set the RequestMethod, as that is done automatically. Finally, if the service really needs an XML document uploaded. Then you won't be able to use the FormData. The format data is only if you are uploading data that matches and HTML form and is encoded with multipart form or url encoded data. If it requires, XML, you will need to construct the XML document yourself and then post the data from that document.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜