我想在单个请求中上传多个图像,我设法在发送单个图像数据时使其工作。这是我发送单个图像数据的代码:
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseUrl: my_url ];
NSMutableRequest *request = [httpClient multipartFormRequestWithMethod:@"POST" path:nil
parameters:nil constructingBodyWithBlock: ^(id <AFMultipartFormData>formData) {
[formData appendPartWithFileData: my_imageData name:@"image" fileName: @"myImage.jpg" mimeType:@"image/jpeg"];
}];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest: request];
[operation start];
在服务器端,我使用 Spring MVC。这是将接收包含多个图像的请求的 Web 服务/端点:
@RequestMapping(value="/test-multiple-upload/{collateralid}", method = RequestMethod.POST)
public @ResponseBody String multipartfilesUpload(
@PathVariable("collateralid") Long collId,
@RequestParam("images[]") CommonsMultipartFile[] images) {
//proccess the image data. save to local or to DB
return "uploaded successful";
}
我的问题是如何使用具有多个图像的 AFNetworking 发出 multipartForm 请求。