简体   繁体   English

ClientHandlerException:找不到MIME媒体类型multipart / form-data

[英]ClientHandlerException: MIME media type, multipart/form-data, was not found

I am using Jersey client to hit a Spring MVC REST Controller for image uploading functionality. 我正在使用Jersey客户端来访问Spring MVC REST Controller,以实现图像上传功能。 I am getting the following exception: 我收到以下异常:

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

My Controller Method to POST the Image: 我的控制器方法来发布图像:

@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";
}

My REST Controller method get the post data: 我的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
}

Is there a solution to this exception. 是否有解决此异常的方法。 I have tried according to the following stack solutions but I am still getting the same exception. 我已经尝试根据以下堆栈解决方案,但是我仍然遇到相同的异常。

Jersey client exception: A message body writer was not found 泽西岛客户端异常:找不到消息正文编写器

Sending multiple files with Jersey: MessageBodyWriter not found for multipart/form-data 使用Jersey发送多个文件:找不到multipart / form-data的MessageBodyWriter

Have you added the dependencies for multipart? 您是否已添加多部分依赖项?

<!-- Jersey client support  -->
      <dependency>
       <groupId>com.sun.jersey</groupId>
       <artifactId>jersey-client</artifactId>
       <version>1.9</version>
      </dependency>

      <dependency>
       <groupId>com.sun.jersey</groupId>
       <artifactId>jersey-json</artifactId>
       <version>1.9</version>
      </dependency>

      <dependency>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>jersey-multipart</artifactId>
        <version>1.9</version>
    </dependency>

      <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
       <version>1.3.2</version>
      </dependency>

    <!-- Apache Commons FileUpload -->
    <dependency>
        <groupId>commons-fileupload</groupId>
        <artifactId>commons-fileupload</artifactId>
        <version>1.3.1</version>
    </dependency>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在JerseyTest中找不到媒体类型= multipart / form-data的MessageBodyWriter - MessageBodyWriter not found for media type=multipart/form-data in JerseyTest Jersey:找不到媒体类型= multipart / form-data的MessageBodyReader - Jersey: MessageBodyReader not found for media type=multipart/form-data org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=multipart/form-data - org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=multipart/form-data 如何解决找不到媒体类型= multipart / form-data错误的MessageBodyWriter - How to resolve MessageBodyWriter not found for media type=multipart/form-data error 找不到适合请求类型 [java.util.LinkedHashMap] 和内容类型 [multipart/form-data] 的 HttpMessageConverter - no suitable HttpMessageConverter found for request type [java.util.LinkedHashMap] and content type [multipart/form-data] enctype multipart/form-data 在多数据类型表单中的使用 - Usage of enctype multipart/form-data in multi data type form 使用Jersey发送多个文件:找不到multipart / form-data的MessageBodyWriter - Sending multiple files with Jersey: MessageBodyWriter not found for multipart/form-data 处理多部分/表单数据 - processing multipart/form-data multipart / form-data的问题 - Issue with multipart/form-data "Quarkus-resteasy-multipart 找不到内容类型多部分\/表单数据类型的编写器" - Quarkus-resteasy-multipart could not find writer for content-type multipart/form-data type
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM