0
votes

I need to upload a image from iOS device to web service. While uploading image i used;

    NSData* pictureData = UIImagePNGRepresentation(originalImage);

Actually it works fine. However the images i uploaded does not show up in IE. I tried uploading both JPG and PNG i can see the images in all other browsers but it does not work in IE. So i thought that it can be about converting it to NSData.

Is there any other way to convert UIImage to NSData?

Or any other idea that might be causing the problem?

Here is the way i upload the image;

NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
[request setValue:contentType forHTTPHeaderField: @"Content-Type"];

NSMutableData *body = [NSMutableData data];

NSData* pictureData = UIImagePNGRepresentation(originalImage);

if (pictureData) {
    [body appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"; filename=\"image.JPG\"\r\n", FileParamConstant] dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
    [body appendData:pictureData];
    [body appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
}

[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
1
the problem most likely isn't on how you upload your image but on how it is displayed on your website.Jerome Diaz
I am uploading it to JIRA with using its own REST services. This functionality is being used by lots of different applications. So there must be something wrong with my code. This is what i am using: linkYiğit Doğuş Özçelik
Besides setting the correct content-type header, you should set the size of the content of the multipart (size of the image data) explicitly. NSURLConnection will do that for the whole message, but I strongly believe not for the multipart.CouchDeveloper

1 Answers

1
votes

You are converting your image to a PNG representation and then you rename it image.JPG

IE might get confused by that. Try to either rename your image to image.PNG or use UIImageJPEGRepresentation