Spring WebFlux: set max file(s) size for uploading files

前端 未结 1 661
一整个雨季
一整个雨季 2021-01-12 14:16

I\'m using flux of FileParts to upload files @RequestPart(FILES) Flux files

And trying to limit maximum size of files. Looks like old wa

相关标签:
1条回答
  • 2021-01-12 15:04

    The Web on Reactive Stack documentation states the following:

    For file parts written to disk, there is an additional maxDiskUsagePerPart property to limit the amount of disk space per part. There is also a maxParts property to limit the overall number of parts in a multipart request. To configure all 3 in WebFlux, you’ll need to supply a pre-configured instance of MultipartHttpMessageReader to ServerCodecConfigurer.

    I was able to apply it via this configuration class:

    @Configuration
    @EnableWebFlux
    public class WebConfig implements WebFluxConfigurer {
    
        @Override
        public void configureHttpMessageCodecs(ServerCodecConfigurer configurer) {
            SynchronossPartHttpMessageReader partReader = new SynchronossPartHttpMessageReader();
            partReader.setMaxParts(1);
            partReader.setMaxDiskUsagePerPart(10L * 1024L);
            partReader.setEnableLoggingRequestDetails(true);
    
            MultipartHttpMessageReader multipartReader = new MultipartHttpMessageReader(partReader);
            multipartReader.setEnableLoggingRequestDetails(true);
    
            configurer.defaultCodecs().multipartReader(multipartReader);
        }
    
    }
    
    0 讨论(0)
提交回复
热议问题