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

查看:349
本文介绍了class com.sun.jersey.core.header.FormDataContentDisposition of content type:multipart / form-data;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用REST API上传文件(我正在使用wildfly Server),我收到此错误:

I'm trying to upload a file using REST API (I'm using wildfly Server), and I'm getting this error:


无法执行:javax.ws.rs.NotSupportedException:找不到类型的消息正文阅读器:class com.sun.jersey.core.header.FormDataContentDisposition of content type:multipart / form-data;

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.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();
        }

    }

}

这是我在pom.xml中使用的依赖项:

And this is the dependencies that I use in my 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>

我的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.

提前致谢。

推荐答案

尝试使用在wildfly中反复使用resersasyaxrs而不是jersy

Try to use resteasyaxrs instead of jersy in wildfly

需要的罐子


  1. 列表项目

  2. resteasyjaxrs.jar

  3. resteasy-multipart-provider.jar

  4. commonsi0.jar

  1. List item
  2. resteasyjaxrs.jar
  3. resteasy-multipart-provider.jar
  4. commonsi0.jar

休息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");
}

这篇关于class com.sun.jersey.core.header.FormDataContentDisposition of content type:multipart / form-data;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆