Disable spring boot multipart upload by controller

前端 未结 3 725
青春惊慌失措
青春惊慌失措 2021-01-12 06:15

I am using spring boot for uploading files. The files sizes are usually about 2GB and we cannot use the default spring boot StandardServletMultipartResolver or

相关标签:
3条回答
  • 2021-01-12 06:57

    This shows how it can be done :

    springboot-large-streaming-file-upload-using-apache-commons-fileupload

    Look at the answer of balajeerc

    0 讨论(0)
  • 2021-01-12 07:11

    It's actually possible to conditionally disable multipary with a custom MultipartResolver, but you should do it at request level.

    With multipart enabled, the files are stored locally on the server, and with multipart off, your controller has to do the parsing manually.

    Since I read so much conflicting information on this topic, I decided to go into the details here https://youtu.be/OpJ0jKRBa1g where I illustrate how to have both strategies coexist at the same time.

    0 讨论(0)
  • 2021-01-12 07:12

    If you enable resolve-lazily, the result is exactly what I think you're asking for.

    spring.servlet.multipart.enabled = true
    spring.servlet.multipart.resolve-lazily = true
    

    Now you can write controllers with either form of signature.

    Pre-parsing by the built-in multipart resolver...

    @PostMapping("/upload1")
    public ResponseEntity<Void> postUpload1(
        @RequestParam("metadata") MultipartFile metadata,
        @RequestParam("payload") MultipartFile payload)
    

    Or post-parsing (which you can parse yourself)...

    @PostMapping(path = "/upload2", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ResponseEntity<Void> postUpload2(HttpServletRequest rawRequest)
    
    0 讨论(0)
提交回复
热议问题