<input id="uploadImageId" type="file" accept="image/*" onChange="angular.element(this).scope().uploadPic(this);">
控制器:
$scope.uploadPic = function(input) {
if (input.files && input.files[0]) {
ContactService.uploadContactImage.upload({
fileName : input.files[0].name
}, input.files[0], function(data) {
});
}
}
};
服务:
uploadContactImage : $resource('/services/api/contacts/uploadContactImage/:fileName',
{
fileName : '@fileName'
}, {
upload : {
method : 'POST',
headers: {'Content-Type': 'multipart/form-data; boundary='}
}
})
接口:
@POST
@Path("/uploadContactImage/{fileName}")
@Produces("application/json")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Map<String, Object> uploadContactImage(
@PathParam("fileName") String fileName,
@FormDataParam("file") InputStream uploadedInputStream,
@FormDataParam("file") FormDataContentDisposition contentDispositionHeader,
@Context HttpServletRequest httpServletRequest) throws GaException {
BufferedImage image = ImageIO.read(uploadedInputStream);
ImageIO.write(image, "jpg", new File("/../../fileName));
}
输出:
java.lang.IllegalArgumentException: image == null!
at javax.imageio.ImageTypeSpecifier.createFromRenderedImage(ImageTypeSpecifier.java:925)
at javax.imageio.ImageIO.getWriter(ImageIO.java:1591)
at javax.imageio.ImageIO.write(ImageIO.java:1520)
请在此指导我我是否错过了要在标头中传递的任何参数?或者我如何在 angularjs 中传递@FormDataParam?