Size configuration when uploading large data in REST in SpringBoot

   When the front-end uploads images in REST mode, the following exception occurs on the Sprintboot server:
The multi-part request contained parameter data (excluding uploaded files) that exceeded the limit for maxPostSize set on the associated connector.
  Refer to this link: http://stackoverflow. com/questions/33232849/increase-http-post-maxpostsize-in-spring-boot
   needs to modify the following two configurations at the same time:
   1. Modify maxPostSize, it seems that it can only be done in the code:
@Bean
	EmbeddedServletContainerCustomizer containerCustomizer() throws Exception {
		return (ConfigurableEmbeddedServletContainer container) -> {
			if (container instanceof TomcatEmbeddedServletContainerFactory) {
				TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
				tomcat.addConnectorCustomizers((connector) -> {
					connector.setMaxPostSize(10000000); // 10 MB
				});
			}
		};

   2. Modify the size limit of multipartFile, either in the code or in the configuration file:
  spring:  
  http:
    multipart:
      max-file-size: 10MB
      max-request-size: 10MB
      maxFileSize: 10MB
      maxRequestSize: 10MB

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326545823&siteId=291194637