Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to upload multiple images without using ASIHTTPRequest
    primarykey
    data
    text
    <p>I want to upload two images to the server with following code can any one please help me, here is my code for post data</p> <pre><code>- (void)uploadPath:(NSString*)path withOptions:(NSDictionary*)options withImageData1:(NSData*)data1 ofImageName1:(NSString *)imageName1 andImageData2:(NSData*)data2 ofImageName2:(NSString *)imageName2 { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSURL *url = [NSURL URLWithString:path relativeToURL:[NSURL URLWithString:baseURLString]]; NSMutableURLRequest *mutableRequest = [[NSMutableURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:90.0]; NSString *boundary = @"-------1234567"; [mutableRequest setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@",boundary] forHTTPHeaderField:@"Content-Type"]; [mutableRequest setHTTPMethod:@"POST"]; NSMutableData *postbody = [NSMutableData data]; for(NSString *key in options) { NSString *value = [options objectForKey:key]; [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\"\r\n\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[value dataUsingEncoding:NSUTF8StringEncoding]]; } [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; //******************* Append 1st Image ************************/ if ([imageName1 isEqualToString:@"picture1.jpg"]) { [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"picture1\"; filename=\"%@\"\r\n",imageName1] dataUsingEncoding:NSUTF8StringEncoding]]; } [postbody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[NSData dataWithData:data1]]; [postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]]; //******************* Append 1st Image ************************/ //******************* Append 2nd Image ************************/ if ([imageName2 isEqualToString:@"picture2.jpg"]) { [postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"picture2\"; filename=\"%@\"\r\n",imageName2] dataUsingEncoding:NSUTF8StringEncoding]]; } [postbody appendData:[[NSString stringWithString:@"Content-Type: application/octet-stream\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]]; [postbody appendData:[NSData dataWithData:data2]]; //******************* Append 2nd Image ************************/ [mutableRequest setHTTPBody:postbody]; urlConnection = [[NSURLConnection alloc] initWithRequest:mutableRequest delegate:self]; if (self.urlConnection) { self.dataXml = [NSMutableData data]; } self.urlConnection = nil; [mutableRequest release]; [pool release]; } </code></pre>
    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.
 

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