Hi Experts..
I tried increase spring.servlet.multipart.max-file-size and max-request-size in SpringBoot2 application.yml file but seem like not working...
Below is SpringBoot2 version in pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Below is application.yml setting
spring:
servlet:
multipart:
max-file-size: -1
max-request-size: -1
data:
rest:
base-path: /api/rest
# http:
# multipart:
# max-file-size: -1
# max-request-size: -1
---
spring:
profiles: sit
servlet:
multipart:
max-file-size: -1
max-request-size: -1
Error message:
2019-03-19 18:36:10.943 DEBUG 44476 --- [nio-8080-exec-1] o.s.security.web.FilterChainProxy : /api/file-service/upload has an empty filter list
2019-03-19 18:36:10.962 ERROR 44476 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MaxUploadSizeExceededException: **Maximum upload size exceeded**; nested exception is java.lang.IllegalStateException: org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field filepond exceeds its maximum permitted size of 104857600 bytes.] with root cause
org.apache.tomcat.util.http.fileupload.FileUploadBase$FileSizeLimitExceededException: The field filepond exceeds its maximum permitted size of 104857600 bytes.
at org.apache.tomcat.util.http.fileupload.FileUploadBase$FileItemIteratorImpl$FileItemStreamImpl$1.raiseError(FileUploadBase.java:630) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.checkLimit(LimitedInputStream.java:76) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.http.fileupload.util.LimitedInputStream.read(LimitedInputStream.java:135) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at java.base/java.io.FilterInputStream.read(FilterInputStream.java:107) ~[na:na]
at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:98) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.http.fileupload.util.Streams.copy(Streams.java:68) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.http.fileupload.FileUploadBase.parseRequest(FileUploadBase.java:293) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.connector.Request.parseParts(Request.java:2846) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.connector.Request.parseParameters(Request.java:3185) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.connector.Request.getParameter(Request.java:1116) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.connector.RequestFacade.getParameter(RequestFacade.java:381) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:84) ~[spring-web-5.1.2.RELEASE.jar!/:5.1.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.2.RELEASE.jar!/:5.1.2.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.1.2.RELEASE.jar!/:5.1.2.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.1.2.RELEASE.jar!/:5.1.2.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at com.dbs.rmg.sg.web.filter.CorsFilter.doFilter(CorsFilter.kt:33) ~[classes!/:2.9.0-SNAPSHOT]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.12.jar!/:9.0.12]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
2019-03-19 18:36:11.013 DEBUG 44476 --- [nio-8080-exec-1] o.s.s.w.u.matcher.AntPathRequestMatcher : Checking match of request : '/error'; against '/'
```
**Comment From: wilkinsona**
Thanks for the report but I cannot reproduce the behaviour you have described. I have successfully uploaded a 300MB file when the max request and file sizes are set to `-1`. If you would like us to spend some more time investigating, please spend some time to provide a complete and minimal example that reproduces the problem.
**Comment From: lkc513**
Hi Wil
i'm using web to call the api for upload, below is my web code design
Below is my API Controller write in kotlin
import com.dbs.rmg.sg.web.storage.FileStorage import org.springframework.stereotype.Controller import org.springframework.beans.factory.annotation.Autowired import org.springframework.web.bind.annotation.PostMapping import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RequestParam import org.springframework.web.bind.annotation.RestController import org.springframework.web.multipart.MultipartFile
@Controller @RequestMapping("/api/file-service") open class FileServiceController {
@Autowired
lateinit var fileStorage: FileStorage
@PostMapping("/upload")
fun upload(@RequestParam("filepond") file: MultipartFile): String {
this.fileStorage.save(file)
return "Upload successful!\n"
}
}
it's success when uploading 100MB file but i do need to upload up to 500MB file daily so i tried to set the application yml as below but seem like it's not capture...
spring: servlet: multipart: max-file-size: -1 max-request-size: -1
Java and Kotlin version
**Comment From: wilkinsona**
Thanks for the code snippets. Unfortunately I can’t afford the time it would take to create an app from them, particularly as some bits are still missing. There’s no pom, for example. If you would like us to spend more time on this, please provide a zip attached to this issue or separate Git repo that contains a minimal app that we can run without modification to reproduce the problem.
**Comment From: lkc513**
Hi Wil,
i found the issue...
@Bean fun multipartConfigElement(): MultipartConfigElement { val factory = MultipartConfigFactory()
factory.setMaxFileSize("102400KB") //KB,MB
factory.setMaxRequestSize("1024000KB")
return factory.createMultipartConfig()
}
i think one of my colleague set this on WebConfig class and clauses the issue after disable this piece of method, my problem solved.
Thanks and sorry for trouble...
**Comment From: nicolasandrieux**
Config with 512MB without deprecated
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.Bean;
import org.springframework.util.unit.DataSize;
import javax.servlet.MultipartConfigElement;
@ServletComponentScan
@SpringBootApplication
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
@Bean
MultipartConfigElement multipartConfigElement() {
MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize(DataSize.ofBytes(512000000L));
factory.setMaxRequestSize(DataSize.ofBytes(512000000L));
return factory.createMultipartConfig();
}
}
**Comment From: itstannus**
This solution does not work for me.
I have tried :
Configuration file transfer in bytes 100MB
spring.servlet.multipart.max-file-size = 100000000 spring.servlet.multipart.max-request-size=100000000
Server properties
server.tomcat.max-http-post-size=1000
server.tomcat.max-swallow-size=1000
```
and MultipartConfigElement multipartConfigElement()
mentioned above .
However both solution do not restrict the request body size of my requests. Please help. I am using spring 5.3.8
Comment From: wilkinsona
@itstannus It's hard to help based on what you've described thus far. If you believe that you have found a bug, please open a new issue with a minimal sample that reproduces the problem and we can take a look. If you're just looking for some help, please ask a question on Stack Overflow or Gitter, as we prefer to use the issue tracker only for bugs and enhancements.