Resteasy and fileupload: get no content-disposition error

瘦欲@ 提交于 2019-12-04 19:17:23

I got the same error when trying to using resteasy and in my case Seam framework. The reason for the error was that Seam MultipartFilter captured the request. What I had to do was to tell the Seam MultipartFilter to only handle multipart requests ending with *.seam.

This way resteasy got the intended request, not the seam filter.

My Rest method:

@POST
@Path("admin/uploadImage")
public String uploadImage(@MultipartForm UploadForm form);

Upload form:

public class UploadForm {

    private byte[] filedata;

    public UploadForm() {
    }

    public byte[] getFileData() {
        return filedata;
    }

    @FormParam("filedata")
    @PartType("application/octet-stream")
    public void setFileData(final byte[] filedata) {
        this.filedata = filedata;
    }


}

components.xml:

    <component class="org.jboss.seam.web.MultipartFilter">
        <property name="createTempFiles">true</property>
        <property name="maxRequestSize">8000000</property>
        <property name="urlPattern">*.seam</property>
    </component>

Even though you might not use Seam I would start looking at the framework you are using and finding out where your request is being handled first.

I got the same error using Resteasy and Spring Boot.

Spring MVC does not configure a MultipartResolver by default, but the Spring Boot MultipartAutoConfiguration does.

Simply add the following to your application.yml to disable the multipart resolver that Spring Boot wants to configure:

spring.http.multipart.enabled: false

If you're using a version of Spring Boot lower than 1.4:

multipart.enabled: false
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!