1

I have Jersey Restful web service that accept multipart file. Its working fine when i tried to upload a file from html multipart form

<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>

and my java webservice code is

@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());

}

But when i tried to upload a image file from my iOS code using AFHTTPRequestOperationManager (AFNetworking 2) i am getting null in InputStream profilePicStream and FormDataContentDisposition fileDetail following are my iOS code to upload the file

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

Any one please help me to solve this issue

Thanks

AMR
  • 63
  • 1
  • 5
  • These links -[link 1](http://stackoverflow.com/questions/19836432/uploading-image-with-afnetworking-2-0) and [link 2](http://stackoverflow.com/questions/19261481/ios-image-upload-via-afnetworking-2-0) might help u out. – nikhil84 Sep 16 '14 at 08:35
  • Thanks Walle, The first Link worked for me.. – AMR Sep 16 '14 at 08:52

1 Answers1

0

These links -link 1 and link 2 might help u out.

So now you could tick and close this question.

Community
  • 1
  • 1
nikhil84
  • 3,235
  • 4
  • 22
  • 43