【问题标题】:Failing image uploading AFHTTPRequestOperationManager图片上传失败 AFHTTPRequestOperationManager
【发布时间】:2014-09-16 08:29:43
【问题描述】:

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

<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);
}];

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

谢谢

【问题讨论】:

  • 这些链接 -link 1link 2 可能会帮助你。
  • 感谢 Walle,第一个链接对我有用..

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


【解决方案1】:

这些链接 -link 1link 2 可能会帮助你。

所以现在你可以勾选并结束这个问题了。

【讨论】:

    猜你喜欢
    • 2014-10-25
    • 2016-04-11
    • 2014-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-02-08
    • 1970-01-01
    相关资源
    最近更新 更多