When uploading the image today, the following error was reported: The service runs exception, Could not parse multipart servlet request; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field file exceeds its maximum allowed size of 1048576 bytes.
SpringBoot defaults to 1M, so it is modified according to the needs.
There are two types, one is configured in the startup class, and the other is configured in application.yml or application.properties.
The first type is added as follows, restart;
multipart: enabled: true max-file-size: 50mb max-request-size: 50mb
The second type is to add the following code to the startup class: MB or KB is OK.
/*** @date:2018/3/5 14:02* @author:hejr* @description: File upload configuration*/@Beanpublic MultipartConfigElement multipartConfigElement() { MultipartConfigFactory factory = new MultipartConfigFactory(); // Maximum factory.setMaxFileSize("5MB"); /// Set the total uploaded data size factory.setMaxRequestSize("50MB"); return factory.createMultipartConfig();}Summarize
The above are the two configuration methods for restricting the size of files or pictures uploaded by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!