Note that there are some explanatory texts on larger screens.

plurals
  1. POSending an image data(NSData) to the server
    primarykey
    data
    text
    <p>I want to send image data to the server, For that, I have appended that data to the HTTP body of the request and sent it. I am using the following code.</p> <pre><code>NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:[NSURL URLWithString:@"http://developers.our-works.com/forms/TestReceiver.aspx"]]; [request setHTTPMethod:@"POST"]; NSString *boundary = [NSString stringWithString:@"---------------------------14737809831466499882746641449"]; NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary]; [request addValue:contentType forHTTPHeaderField: @"Content-Type"]; // now lets create the body of the post NSMutableData *body = [NSMutableData data]; [body appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"userfile\"; filename=\"%@\"\r\n",tempFileName] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [body appendData:[NSData dataWithData:imgdata]]; [body appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; //data into the string..... verifying............ NSString *strTest = [[NSString alloc] initWithData:body encoding:NSUTF8StringEncoding]; NSLog(@"%@",strTest); // setting the body of the post to the request [request setHTTPBody:body]; // now lets make the connection to the web NSData *returnData = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; </code></pre> <p>Now I have to send the NSData of the two different images. So, just want to ask that, can I send those two different image's NSData within the same body as above. Or, I have to code the same thing for the other image's Data.</p> <p>Please, help me out of this. Thanking 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.
 

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