我将多张图片发布到服务器 url,但我面临一个问题。发布图像数据后,服务器只获取我首先发送的图像数据。其余数据为空。但在发布时我可以打印数据(NSLog)
请帮助我理解问题在这里给出我的代码
上传ImageViewController.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];
}
上传图片.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];
}
}