I am posting multiple images to server url,But i am facing one issue.
After posting the image datas,The serever get only the image data i send first.The remaining datas are null.But at the time of posting i can print the datas (NSLog)
Please help me to understand the problem
Giving my code here
UploadImageViewController.m
-(IBAction)upPic:(id)sender{
UploadImage *up_image = [[UploadFood alloc] init];
[up_image sendServerRequests:[NSDictionary dictionaryWithObjectsAndKeys:@"pic1.jpg",@"filename",@"pic2.jpg",@"filename2", nil] file:sharedClass.picData file1:sharedClass.picData2];
}
UploadImage.m
-(void)sendServerRequests:(NSDictionary *)bits file:(NSData *)file file1:(NSData *)file1 file2:(NSData *)file2 {
NSLog(@"file %@",file );
[postbody appendData:[NSData dataWithData:file]];
[postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image2\"; filename=\"%@\"\r\n", [bits objectForKey:@"filename2"]] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"file1 %@",file1);
[postbody appendData:[NSData dataWithData:file1]];
[postbody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"image3\"; filename=\"%@\"\r\n", [bits objectForKey:@"filename3"]] dataUsingEncoding:NSUTF8StringEncoding]];
[postbody appendData:[@"Content-Type: application/octet-stream\r\n\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
NSLog(@"file2 %@",file2); // i am able to print data here
[postbody appendData:[NSData dataWithData:file2]];
[postbody appendData:[[NSString stringWithFormat:@"\r\n--%@--\r\n",boundary] dataUsingEncoding:NSUTF8StringEncoding]];
[request setHTTPBody:postbody];
conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if (conn) {
webData = [NSMutableData data];
}
}
Hey Nithin MK AS per your code you did all things perfectly ok.
in the current situation, only the first file is uploading on the server. I think if you are not uploading the first file and uploading the second file it would be uploaded.
So I suggest that you can use the array for this. if your web service using php/.net then you can use the array for the file name.
so try with use
and also please check your web service with this.
Thanks.