如何使用ASIFormDataRequest从uiimagePickerController上传照片?

时间:2012-01-10 01:47:47

标签: iphone cocoa-touch ipad asihttprequest asiformdatarequest

我使用UIImagePickerController的委托来选择照片并将其放到服务器但问题是我不知道如何使用ASIFormDataRequest做到这一点我不知道应该使用哪个键作为info参数?

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

NSString *str = [NSString stringWithFormat:@"http://www.siteweb.com/api/v2/businesses/%@/pics.xml",entry.permalink];
NSURL *url = [NSURL URLWithString:str];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
request.delegate = self;

[request startAsynchronous];

[self dismissModalViewControllerAnimated:YES];
}

1 个答案:

答案 0 :(得分:1)

像这样:

  

[request addFile:(NSString *)filePath forKey:(NSString *)key];

事先得到这样的图像:

  

UIImage * image =(UIImage *)[info   valueForKey:UIImagePickerControllerOriginalImage];

     

[UIImageJPEGRepresentation(image,1.0)writeToFile:filePath   原子:YES];