spring-guides / gs-uploading-files

Uploading Files :: Learn how to build a Spring application that accepts multi-part file uploads.

Home Page:http://spring.io/guides/gs/uploading-files/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

max-file-size doesn't seem to do anything

andrewe123 opened this issue · comments

I might be misunderstanding how the max-size configuration is supposed to be applied, but it doesn't seem to do anything.

You can set it to 0B (or anything else), and see that the configuration is picked up.

spring.servlet.multipart.max-file-size=0B
spring.servlet.multipart.max-request-size=0B
    private final StorageService storageService;
    private MultipartConfigElement multipartConfigElement;

    @Autowired
    public FileUploadController(StorageService storageService, MultipartConfigElement multipartConfigElement) {
        this.storageService = storageService;
        this.multipartConfigElement = multipartConfigElement;
    }
...
    @PostMapping("/")
    public String handleFileUpload(@RequestParam("file") MultipartFile file,
            RedirectAttributes redirectAttributes) {
      multipartConfigElement.getMaxFileSize(); // Value is 0 when inspected.
...

But it doesn't seem to do anything. The 16B test file still gets saved without any impact from the max-size configuration.

Although not directly related to this app, the documentation here lead me to believe that setting the max-size values would automatically produce some error, and if that's not the case it might be helpful to clarify.

The configuration does work, but doesn't seem to work with MockMVC.

When I ran the application and did a test with postman it worked.

https://stackoverflow.com/a/55532976/5654793