EDIT:
The file data you are uploading should be encoded using Base64; you can do that by means of NSData+Base64 and then use:
[body appendData:[imageData1 base64EncodedString];
to send the file data, whereby I assume that imageData1
was defined as:
NSData* imageData = UIImagePNGRepresentation(image);
and image
is a UIImage
.
OLD ANSWER:
This is an example coming from the HTML 4.0.1 standard (very end of the document):
Content-Type: multipart/form-data; boundary=AaB03x
--AaB03x
Content-Disposition: form-data; name="submit-name"
Larry
--AaB03x
Content-Disposition: form-data; name="files"
Content-Type: multipart/mixed; boundary=BbC04y
--BbC04y
Content-Disposition: file; filename="file1.txt"
Content-Type: text/plain
... contents of file1.txt ...
--BbC04y
Content-Disposition: file; filename="file2.gif"
Content-Type: image/gif
Content-Transfer-Encoding: binary
...contents of file2.gif...
--BbC04y--
--AaB03x--
Notice that the files are listed all together in a multipart/mixed list.
So you can try with the code:
//-- new part in multipart/form-data
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Disposition: form-data; name=\"files\" dataUsingEncoding:NSUTF8StringEncoding]];
//-- new multipart/mixed
[body appendData:[[NSString stringWithFormat:@"multipart/mixed; boundary=%@", mixedBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: file; filename=\"%@\"\r\n", FileParamConstant1] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: image/jpeg\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:imageData1];
[body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", mixedBoundary] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: file; filename=\"%@\"\r\n", FileParamConstant2] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithString:@"Content-Type: image/jpeg\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:imageData2];
[body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
Take care of changing the filename
and name
attributes and it should work.