サーバーのURLに複数の画像を投稿していますが、1つの問題に直面しています。画像データを投稿した後、サーバーは最初に送信した画像データのみを取得します。残りのデータはnullですが、投稿時にデータを印刷できます(NSLog)
問題を理解するのを手伝ってくださいここに私のコードを与える
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];
}
}