我正在使用Jersey客户端来命令Spring MVC REST Controller进行图像上传功能 . 我收到以下异常:
com.sun.jersey.api.client.ClientHandlerException: A message body writer for Java type, class org.springframework.web.multipart.commons.CommonsMultipartFile, and MIME media type, multipart/form-data, was not found
我的控制器方法来POST图像:
@RequestMapping(value = "/file/upload", method = RequestMethod.POST)
public String fileUpload(@RequestParam("fileUpload") MultipartFile file,
Model model, HttpServletRequest request, HttpServletResponse response)
{
try
{
ClientConfig config = new DefaultClientConfig();
com.sun.jersey.api.client.Client client = com.sun.jersey.api.client.Client.create(config);
WebResource webResource = client.resource("/save-image");
ClientResponse responseMsg = webResource
.type(MediaType.MULTIPART_FORM_DATA)
.post(ClientResponse.class, file);
}
catch (Exception e)
{
logger.error("Exception in fileUpload()", e);
return "error";
}
return "success";
}
我的REST Controller方法获取帖子数据:
@ResponseBody
@Consumes(MediaType.MULTIPART_FORM_DATA)
@RequestMapping(value = "/save-image", method = RequestMethod.POST)
public String saveImage(@FormDataParam("file") MultipartFile file, ModelMap
model)
{
//Code to save the image
}
是否有解决此异常的方法 . 我已经尝试过根据以下堆栈解决方案,但我仍然得到相同的异常 .
Jersey client exception: A message body writer was not found
Sending multiple files with Jersey: MessageBodyWriter not found for multipart/form-data
1 回答
您是否为multipart添加了依赖项?