更新时间:2023-01-15 15:18:36
我意识到,我当前的代码将直接将上传文件存储在内存中.有两种方法可以解决此问题.
I realized that, my current code will store the upload files in memory directly. There are 2 ways to solve this problem.
@EnableWebFlux
@EnableWebFlux
on your Router or Controller
@Configuration
@EnableWebFlux
class WebController(
) { }
DelegatingWebFluxConfiguration
扩展到路由器或控制器
DelegatingWebFluxConfiguration
to your Router or Controller @Configuration
class WebController(
): DelegatingWebFluxConfiguration() { }
为什么可以解决上传大文件的问题?
Why does it solve the uploading large file problem?
以上两种方法将自动使用晚餐类的方法 configureHttpMessageCodecs(configurer:ServerCodecConfigurer)
https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-codecs-multipart
These 2 ways above will be automatically used a supper class's method configureHttpMessageCodecs(configurer: ServerCodecConfigurer)
https://docs.spring.io/spring-framework/docs/current/reference/html/web-reactive.html#webflux-codecs-multipart
默认情况下,使用DefaultPartHttpMessageReader,但是可以通过ServerCodecConfigurer进行更改.有关DefaultPartHttpMessageReader的更多信息,请参考DefaultPartHttpMessageReader的javadoc.
By default, the DefaultPartHttpMessageReader is used, but this can be changed through the ServerCodecConfigurer. For more information about the DefaultPartHttpMessageReader, refer to to the javadoc of DefaultPartHttpMessageReader.
如您所见, ServerCodecConfigurer
将默认使用DefaultPartHttpMessageReader.
As you can see ServerCodecConfigurer
will use DefaultPartHttpMessageReader by default.
DefaultPartHttpMessageReader
具有此重要属性 MaxInMemorySize
(如果内存已满,则存储在磁盘中)
DefaultPartHttpMessageReader
has this important properties MaxInMemorySize
(if memory full, store in disk)