失败的图像上传AFHTTPRequestOperationManager

时间:2014-09-16 08:29:43

标签: ios iphone web-services jersey afnetworking-2

我有Jersey Restful Web服务,接受多部分文件。当我尝试从html multipart表单上传文件时它工作正常

<form action="ws/picture/update" method="post" enctype="multipart/form-data">
  <p>
   Select a file : <input type="file" name="file" size="50" />
   <input type="text" name="userId" value=""/>
  </p>
 <input type="submit" value="Upload It" />
</form>

我的java webservice代码是

@POST
@Path("/picture/update")
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)   
public String userUpdateProfPic(
        @FormDataParam("file") InputStream profilePicStream,
        @FormDataParam("file") FormDataContentDisposition fileDetail,
        @FormDataParam("userId") String userId) {
     log.info("profilePicStre>"+profilePicStream);
     log.info("Inside User Profile Image Updation."+fileDetail.getFileName());

}

但是当我尝试使用AFHTTPRequestOperationManager(AFNetworking 2)从我的iOS代码上传图像文件时,我在InputStream profilePicStreamFormDataContentDisposition fileDetail中变为空 以下是我上传文件的iOS代码

NSData *imageData = UIImagePNGRepresentation(image);
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
        [manager POST:@"http://localhost:8888/ws/picture/update"
           parameters:@{@"userId":@"1"}
constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
    [formData appendPartWithFileData:imageData name:@"avatar" fileName:@"avatar.jpg" mimeType:@"image/jpeg"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"Success: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

任何人请帮我解决这个问题

由于

1 个答案:

答案 0 :(得分:0)

这些链接 - link 1link 2可能会帮助您解决问题。

所以现在你可以打勾并关闭这个问题。