Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just tried this and this works for me. I have uploaded an image and passed few required paramters to the API. NSMutableURLRequest * theURLrequest =[[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:UPLOAD_FILE_URL]]; [theURLrequest setHTTPMethod:@"POST"];</p> <pre><code>NSString *boundary = @"---------------------------FOO"; // Setting Content Type to multipart NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary]; [theURLrequest addValue:contentType forHTTPHeaderField: @"Content-Type"]; NSMutableData *postbody = [NSMutableData data]; // setting another parameter like any file attribute [postbody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"param1_name\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[[NSString stringWithFormat:@"%@\r\n", valueOfParam1ToBeSentOnserver] dataUsingEncoding:NSUTF8StringEncoding]]; // setting another parameter like any file attribute [postbody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"param2_name\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[[NSString stringWithFormat:@"%d\r\n", valueOfParam2ToBeSentOnserver] dataUsingEncoding:NSUTF8StringEncoding]]; ////////////////// // setting up data bytes of file to be sent and file name [postbody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"file\"; filename=\"%@\"\r\n", documentName] dataUsingEncoding:NSUTF8StringEncoding]]; // Setting type of contents being sent NSString *contentTypeMime = @"image/jpeg"; [postbody appendData:[[NSString stringWithFormat:@"Content-Type: %@\r\n\r\n",contentTypeMime] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[NSData dataWithData:pDataToUpload]]; [postbody appendData:[[NSString stringWithFormat:@"\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];; [postbody appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]]; ///////////////////////////////////// [theURLrequest setValue:[NSString stringWithFormat:@"%d",[postbody length]] forHTTPHeaderField:@"Content-Length"]; [theURLrequest setHTTPBody:postbody]; //Adding basic authentication in the request NSString* authString=[NSString stringWithFormat:@"%@:%@",pUserName,pPassword]; NSData* authData=[authString dataUsingEncoding:NSASCIIStringEncoding]; NSString* authValue=[NSString stringWithFormat:@"Basic %@", [authData base64EncodedString]]; [theURLrequest addValue:authValue forHTTPHeaderField:@"Authorization"]; NSURLConnection *temp=[[NSURLConnection alloc] initWithRequest:theURLrequest delegate:self]; self.mConnection=temp; [theURLrequest release]; [temp release]; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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