spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Servlet Multipart Configs related to file size aren't working

Open akshaydk-buku opened this issue 3 years ago • 5 comments

Hi Team,

For specifying the maximum size of a file that is acceptable to be uploaded to the server, we specify these options in the application properties

spring.servlet.multipart.maxFileSize=15MB
spring.servlet.multipart.maxRequestSize=15MB

These are working for a regular spring boot service running on it's default web server i.e Tomcat, but the same options does not seem to work when included in spring cloud gateway running on it's default web server i.e Netty

A spring boot service throws MaxFileLimitExceeded option when I try to upload a file(mp4 video) > 15MB in size

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;

Whereas spring cloud gateway does not block the request and allow to proceed through

akshaydk-buku avatar Aug 08 '22 16:08 akshaydk-buku

Spring Boot version: 2.3.5.RELEASE & Java version: 1.8 Spring Cloud Train version: 2021.0.1 & Java version: 11

akshaydk-buku avatar Aug 08 '22 16:08 akshaydk-buku

There is no size limit for uploading files on spring-cloud-gateway, check the specific application service configuration

ghostspiders avatar Aug 15 '22 16:08 ghostspiders

What if I want to impose the size limit of files as I'd do on Zuul gateway with the below config

spring.servlet.multipart.maxFileSize=15MB spring.servlet.multipart.maxRequestSize=15MB

How do I achieve the same via Spring cloud gateway? If that's not possible, are there any alternatives?

akshaydk-buku avatar Aug 15 '22 17:08 akshaydk-buku

spring.servlet.multipart.maxFileSize=15MB spring.servlet.multipart.maxRequestSize=15MB These don't work in spring-cloud-gateway, custom filter restricts files

ghostspiders avatar Aug 15 '22 17:08 ghostspiders

Got it. Thanks

akshaydk-buku avatar Aug 16 '22 04:08 akshaydk-buku

Gateway is not a servlet application, hence none of those will work. see https://stackoverflow.com/questions/57424649/spring-webflux-set-max-files-size-for-uploading-files

spencergibb avatar Jan 06 '23 23:01 spencergibb