Is there a max file size when uploading as a Multipart File

前提是你 提交于 2019-12-11 23:31:58

问题


  HttpPost post = new HttpPost(properties.getPropert("system.api.url"));
            post.setHeader("Accept", "application/json");
            MultipartEntity entity = new MultipartEntity(
                    HttpMultipartMode.BROWSER_COMPATIBLE);
            entity.addPart("file", new FileBody(file, event.getMIMEType()));
            post.setEntity(entity);  

This is how I upload the file as a Multipart file to my rest controller. Is there a max file size that can be uploaded or is there any way that I can define a max file size foe this kind of uploading. I use this code in my Vaadin client side.


回答1:


Try this in your config:

@Bean
public MultipartResolver multipartResolver() {
    return new StandardServletMultipartResolver();
}

@Bean
MultipartConfigElement multipartConfigElement() {
    MultiPartConfigFactory factory = new MultiPartConfigFactory();
    factory.setMaxFileSize(env.getRequiredProperty("MAX.FILE.SIZE"));
    factory.setMaxRequestSize(env.getRequiredProperty("MAX.FILES.SIZE"));
    factory.setFileSizeThreshold(env.getRequiredProperty("MAX.MEMORY.SIZE"));
    factory.setLocation(env.getRequiredProperty("IMAGE.PROCESSOR.UPLOADTMP"));

    return factory.createMultipartConfig();
}

I assume that env is Spring configuration environment variables. Or just put values instead.



来源:https://stackoverflow.com/questions/18394259/is-there-a-max-file-size-when-uploading-as-a-multipart-file

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