I am developing an iOS application using .NET web service. In one of the web services, I have to send image as HttpPostedFileBase in a parameter called "file", which will return the image URL and status parameters as response. Actually I am not sure what is HttpPostedFileBase. But I am trying to send that as bytes. I am getting image URL as null from WS. I guess the WS call works fine, but the problem is in the way I send the image. I am using the following code to append image data to HTTP body.
NSData *imageData = UIImageJPEGRepresentation(image, 1);
[postData appendData:[[NSString stringWithFormat:@"--%@\r--\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"Content-Disposition: form-data; name=\"file\"; filename=\"file.jpeg\"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[postData appendData:imageData];
[request addValue:@"application/octet-stream" forHTTPHeaderField:@"Content-Type"];
[request addValue:[NSString stringWithFormat:@"%i", [postData length]] forHTTPHeaderField:@"Content-Length"];
[postData appendData:[[NSString stringWithFormat:@"--%@\r--\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
Please let me know how can I get this working. Let me know if you need anymore detail.
Thanks.