简体   繁体   English

内容类型的com.sun.jersey.core.header.FormDataContentDisposition类:multipart / form-data;

[英]class com.sun.jersey.core.header.FormDataContentDisposition of content type: multipart/form-data;

I'm trying to upload a file using REST API (I'm using wildfly Server), and I'm getting this error: 我正在尝试使用REST API上传文件(我正在使用wildfly服务器),但出现此错误:

failed to execute: javax.ws.rs.NotSupportedException: Could not find message body reader for type: class com.sun.jersey.core.header.FormDataContentDisposition of content type: multipart/form-data; 执行失败:javax.ws.rs.NotSupportedException:找不到类型的消息正文阅读器:类com.sun.jersey.core.header.FormDataContentContent内容类型:multipart / form-data;

This my code: 这是我的代码:

@javax.ws.rs.ApplicationPath("webresources")
public class ApplicationConfig extends Application {

    @Override
    public Set<Class<?>> getClasses() {
        Set<Class<?>> resources = new java.util.HashSet<>();
        addRestResourceClasses(resources);

        return resources;
    }

    private void addRestResourceClasses(Set<Class<?>> resources) {
        resources.add(com.services.DocumentFacadeREST.class);
    }

}

@Stateless
@Path("documents")
public class DocumentFacadeREST{

    @POST
    @Path("/upload")
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @Produces(MediaType.TEXT_PLAIN)
    public String uploadFile(
            @FormDataParam("file") InputStream uploadedInputStream,
            @FormDataParam("file") FormDataContentDisposition fileDetail) {

        String uploadedFileLocation = "E://uploadFileRest/"+ fileDetail.getFileName();

        // save it
        writeToFile(uploadedInputStream, uploadedFileLocation);

        String output = "File uploaded to : " + uploadedFileLocation;

        return output;

    }

    // save uploaded file to new location
    private void writeToFile(InputStream uploadedInputStream, String uploadedFileLocation) {

        try {
            OutputStream out = new FileOutputStream(new File(
                    uploadedFileLocation));
            int read = 0;
            byte[] bytes = new byte[1024];

            out = new FileOutputStream(new File(uploadedFileLocation));
            while ((read = uploadedInputStream.read(bytes)) != -1) {
                out.write(bytes, 0, read);
            }
            out.flush();
            out.close();
        } catch (IOException e) {

            e.printStackTrace();
        }

    }

}

And this is the dependencies that I use in my pom.xml: 这是我在pom.xml中使用的依赖项:

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

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-client</artifactId>
    <version>1.17.1</version>
</dependency>

 <dependency>
       <groupId>org.hornetq</groupId>
       <artifactId>hornetq-core</artifactId>
       <version>snap-r9548</version>
 </dependency>

My html form: 我的HTML表单:

   <form action="webresources/documents/upload2" method="post" enctype="multipart/form-data">

      <p>
          Select a file : 
          <input type="file" name="file" size="45" />
      </p>
      <input type="submit" value="Upload" />
   </form>

Please can you help me to know why I got the error, I spent all the day in investigation without any result. 请您帮我知道为什么会出错,我整天都在调查中,没有任何结果。

Thanks in advance. 提前致谢。

Try to use resteasyaxrs instead of jersy in wildfly 尝试在野蝇中使用resteasyaxrs代替jersy

jars needed 需要的罐子

  1. List item 项目清单
  2. resteasyjaxrs.jar resteasyjaxrs.jar
  3. resteasy-multipart-provider.jar resteasy-multipart-provider.jar
  4. commonsi0.jar commonsi0.jar

Rest Api 休息阿皮

@Path("/uploadfile")
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response uploadFile(MultipartFormDataInput input) {
    Map<String, List<InputPart>> uploadForm = input.getFormDataMap();
    List<InputPart> inputParts = uploadForm.get("file");
}

暂无
暂无

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

相关问题 找不到类com.sun.jersey.core.header.FormDataContentDisposition,ContentType:multipart / form-data的邮件正文阅读器 - No message body reader has been found for class com.sun.jersey.core.header.FormDataContentDisposition, ContentType: multipart/form-data javax.ws.rs.NotSupportedException:找不到以下类型的消息正文阅读器:com.sun.jersey.core.header.FormDataContentDisposition类 - javax.ws.rs.NotSupportedException: Could not find message body reader for type: class com.sun.jersey.core.header.FormDataContentDisposition 没有找到类com.sun.jersey.core.header.FormDataContentDisposition的消息正文阅读器 - No message body reader has been found for class com.sun.jersey.core.header.FormDataContentDisposition 请求不包含多部分/表单数据或多部分/混合流,内容类型标头为false - the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is false Jersey:找不到媒体类型= multipart / form-data的MessageBodyReader - Jersey: MessageBodyReader not found for media type=multipart/form-data 如何将带有“ Content-Type”标题的数据发布为“ multipart / form-data” - How to post data with “Content-Type ” header as “multipart/form-data” 多部分/表单数据之间的空白问题; &amp; 内容类型标题中的边界 - White-space issue between multipart/form-data; & boundary in Content-Type Header 使用 header Content-Type:multipart/form-data 发送 java POST 请求? - Send the java POST request with header Content-Type:multipart/form-data? 请求不包含 multipart/form-data 或 multipart/mixed 流,内容类型标头是 application/x-www-form-urlencoded - the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is application/x-www-form-urlencoded 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
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM