I tried to send an image and some text information with HTTP post, but for some reason the post method doesn't send the image but only the text information.
This is my method.
UIImage *image = self.imgBtnPhoto.imageView.image; //is a photo taken and viewed in button.
NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(image)];
NSString *post = [NSString
stringWithFormat:
@"author=%@&comment=%@&comment_post_ID=%@&attachment=%@",
strUsername,
stredtComment,
strIDArgument,
imageData];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"https://myUrl.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(conn) {
NSLog(@"Connection Successful"); //The post is sended and viewed in my WebSite without image!
} else {
NSLog(@"Connection could not be made");
}
Where is the mistake?
Regards