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