我有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 profilePicStream
和FormDataContentDisposition 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);
}];
任何人请帮我解决这个问题
由于