This is code I use to send a file to my server using an HTTP POST command
- (NSURLRequest *)fileUploadRequestWithURL: (NSURL *)url
boundry: (NSString *)boundry
data: (NSData *)data
{
NSMutableURLRequest * urlRequest = [NSMutableURLRequest requestWithURL:url];
// set up the request
[urlRequest setHTTPMethod:@"POST"];
[urlRequest setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundry] forHTTPHeaderField:@"Content-Type"];
// allocate memort for the data
NSMutableData *postData = [NSMutableData dataWithCapacity:[data length] + 512];
// set the data
[postData appendData:[[NSString stringWithFormat:@"--%@\r\n",boundry] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"data\"; filename=\"%@\"\r\n", [filePath lastPathComponent]] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:data];
[postData appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundry] dataUsingEncoding:NSUTF8StringEncoding]];
// append to the request
[urlRequest setHTTPBody:postData];
// return the request
return urlRequest;
}