How can i upload Photo from imagePickerController using ASIFormDataRequest?

193 views Asked by At

I use the delegate of UIImagePickerController for choosing a photo and put it to the server but the problem is i don't know how can i do that using ASIFormDataRequest and i don't know what key should use for the info parameter?

- (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

There are 1 answers

1
Michael Frederick On BEST ANSWER

Like this:

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

Get the image like this beforehand:

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

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