问题
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