我必须配置服务器端以使用 Spring 使用 RestKit 0.2 上传图像。
我使用以下代码进行上传:
NSMutableURLRequest *request = [[RKObjectManager sharedManager] multipartFormRequestWithObject:obj
method:RKRequestMethodPOST
path:nil
parameters:nil
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
[formData appendPartWithFileData:UIImageJPEGRepresentation(obj.image, 1.0)
name:@"image"
fileName:@"image.jpg"
mimeType:@"image/jpeg"];
}];
RKObjectRequestOperation *operation = [[RKObjectManager sharedManager] objectRequestOperationWithRequest:request
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
NSLog(@"%@", [mappingResult firstObject]);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
}];
[[RKObjectManager sharedManager] enqueueObjectRequestOperation:operation];
我的 WS 方面:
@RequestMapping(value = "findMatch", method = RequestMethod.POST)
public void findMatch(@RequestParam(value = "image") Part image){
// ...
}
当我尝试上传图片时出现错误:客户端发送的请求在语法上不正确。
我的问题是,图像参数的名称是什么?
谢谢。