I know very well that you may count this thread as duplicate just because multiple times this question was asked in different ways. I did not find any solution from the existing questions on this forum and thus i'm going to make a new thread.
Here, I've a code for uploading multiple images at a time. So, please note down the sentence that is "multiple images upload".
I want to upload 1 or 2 or 3 or 4 images along with some text parameters and the issue that i'm facing is "same image is uploaded multiple times" mean single image having multiple times on server.
Example :
NSString *urlString = [NSString stringWithFormat:@"%@/MultipleImageUpload",soapAction];
NSMutableURLRequest *theRequest = [[NSMutableURLRequest alloc] init];
[theRequest setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[theRequest setHTTPShouldHandleCookies:NO];
[theRequest setTimeoutInterval:60];
[theRequest setURL:[NSURL URLWithString:urlString]];
[theRequest setHTTPMethod:@"POST"];
NSMutableData *body = [NSMutableData data];
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@",BOUNDARY_MULTIPART_IMAGE];
[theRequest addValue:contentType forHTTPHeaderField: @"Content-Type"];
//parameter SecurityCode
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", BOUNDARY_MULTIPART_IMAGE] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"SecurityCode\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[SEC_CODE dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
//parameter LoggedInUserID
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", BOUNDARY_MULTIPART_IMAGE] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"LoggedInUserID\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@“23433” dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
//parameter Device
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", BOUNDARY_MULTIPART_IMAGE] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"Device\"\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@“iPhone” dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
for (int i=0; i<[arrImgs count]; i++) {
UIImage* image = [arrImgs objectAtIndex:i];
NSData *imgData = UIImageJPEGRepresentation(image, 1.0);
[body appendData:[[NSString stringWithFormat:@"--%@\r\n", BOUNDARY_MULTIPART_IMAGE] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"product_photo\"; filename=\"%d.jpg\"\r\n", i] dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[@"Content-Type: image/jpeg\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
[body appendData:[NSData dataWithData:imgData]];
[body appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
}
// close form
[body appendData:[[NSString stringWithFormat:@"--%@--\r\n", BOUNDARY_MULTIPART_IMAGE] dataUsingEncoding:NSUTF8StringEncoding]];
// setting the body of the post to the request
[theRequest setHTTPBody:body];
return theRequest;
Please let me know if anyone has the solution for this one ..
Thanks,
Nilesh M. Prajapati