I have to upload an image to server for which I wrote code using NSMutableURLRequest like this
NSString *boundary = [NSString stringWithString:@\"----------
Uploading file to server using ASIFormDataRequest
-(void)uploadFile{
NSURL *url = [NSURL URLWithString: photoUploadURLString];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setUseKeychainPersistence:YES];
//if you have your site secured by .htaccess
//[request setUsername:@"login"];
//[request setPassword:@"password"];
NSString *fileName = [NSString stringWithFormat:@"ipodfile%@.jpg",self.fileID];
[request addPostValue:fileName forKey:@"name"];
// Upload an image
NSData *imageData = UIImageJPEGRepresentation([UIImage imageName:fileName])
[request setData:imageData withFileName:fileName andContentType:@"image/jpeg" forKey:@"userfile"];
[request setDelegate:self];
[request setDidFinishSelector:@selector(uploadRequestFinished:)];
[request setDidFailSelector:@selector(uploadRequestFailed:)];
[request startAsynchronous];
}
- (void)uploadRequestFinished:(ASIHTTPRequest *)request{
NSString *responseString = [request responseString];
NSLog("Upload response %@", responseString);
}
- (void)uploadRequestFailed:(ASIHTTPRequest *)request{
NSLog(@" Error - Statistics file upload failed: \"%@\"",[[request error] localizedDescription]);
}
Note I was typing from memory so you may have some misspellings.