Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS: Uploading image to server, cannot be opened
    primarykey
    data
    text
    <p>I am using the following code to upload an image to my servlet.</p> <pre><code>NSData *data = [NSData dataWithData:UIImagePNGRepresentation([UIImage imageNamed:@"jesus.png"])]; NSString *urlString = @"http://localhost:8080/MyServlet/MyServlet?filename=jesus.png"; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init]; [request setURL:[NSURL URLWithString:urlString]]; [request setHTTPMethod:@"POST"]; NSString *boundary = @"_187934598797439873422234"; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary]; [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; NSMutableData *body = [NSMutableData data]; [body appendData:[[NSString stringWithFormat:@"Content-Length %d\r\n\r\n", [data length] ] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[NSData dataWithData:data]]; [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [request setHTTPBody:body]; [request addValue:[NSString stringWithFormat:@"%d", [body length]] forHTTPHeaderField:@"Content-Length"]; NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; NSString *returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding]; NSLog(@"%@", returnString); </code></pre> <p>Its getting uploaded the image and saving this image into a particular mac desktop path. But, when i try to open that image, it says "The file couldn't be opened, it may damaged or use a file format that Preview doesn't recognize".</p> <p>I saw the image file is having the correct size.</p> <p>What could be the reason for not able to open this image file after uploaded from my iOs client? Could someone please suggest me?</p> <p>Thank you.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload