gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 17:01:39 25 4
gpt4 key购买 nike

我正在使用FileParts的flux来上传文件@RequestPart(FILES) Flux<FilePart> files

并尝试限制文件的最大大小。看起来旧方法不起作用:

spring.servlet.multipart.max-file-size=1MB
spring.servlet.multipart.max-request-size=1MB

而且我没有任何方法来获取 FilePart 中的文件大小界面。那么有没有办法限制 webflux 中上传文件的最大大小,而不复制它呢?我知道有像 Content-Length 这样的标题,但它看起来并不安全。

最佳答案

Web on Reactive Stack documentation声明如下:

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.

我能够通过这个配置类应用它:

@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);
}

}

关于java - Spring WebFlux : set max file(s) size for uploading files,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57424649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com