请教, spirng webflux 上传文件multipartData 没有数据的问题

如下代码, 控制台没有任何打印输出,获取不到上传文件的数据,请问代码有什么问题?谢谢。

public Mono<ServerResponse> put(ServerRequest request) {
    request.multipartData()
            .map(it -> {
                System.out.println("#############");
                return it.get("files");
            })
            .subscribe(System.out::println);
   
    return ServerResponse.ok().bodyValue("ok123");
}

请求测试,head 是 multipart/form-data

你看看debug日志,日志到哪儿了。

debug日志如下,貌似没有错误提示

[or-http-epoll-2] io.netty.buffer.AbstractByteBuf          : -Dio.netty.buffer.checkAccessible: true
[or-http-epoll-2] io.netty.buffer.AbstractByteBuf          : -Dio.netty.buffer.checkBounds: true
[or-http-epoll-2] i.n.util.ResourceLeakDetectorFactory     : Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@2a6deebb
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] New http connection, requesting read
[or-http-epoll-2] reactor.netty.transport.TransportConfig  : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Initialized pipeline DefaultChannelPipeline{(reactor.left.httpCodec = io.netty.handler.codec.http.HttpServerCodec), (reactor.left.httpTrafficHandler = reactor.netty.http.server.HttpTrafficHandler), (reactor.right.reactiveBridge = reactor.netty.channel.ChannelOperationsHandler)}
[or-http-epoll-2] io.netty.util.Recycler                   : -Dio.netty.recycler.maxCapacityPerThread: 4096
[or-http-epoll-2] io.netty.util.Recycler                   : -Dio.netty.recycler.maxSharedCapacityFactor: 2
[or-http-epoll-2] io.netty.util.Recycler                   : -Dio.netty.recycler.linkCapacity: 16
[or-http-epoll-2] io.netty.util.Recycler                   : -Dio.netty.recycler.ratio: 8
[or-http-epoll-2] io.netty.util.Recycler                   : -Dio.netty.recycler.delayedQueue.ratio: 8
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Increasing pending responses, now 1
[or-http-epoll-2] reactor.netty.http.server.HttpServer     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Handler is being applied: org.springframework.http.server.reactive.ReactorHttpHandlerAdapter@440f9851
[or-http-epoll-2] o.s.w.s.adapter.HttpWebHandlerAdapter    : [dd675c9a-1] HTTP PUT "/api/object/upload"
[or-http-epoll-2] o.s.w.r.f.s.s.RouterFunctionMapping      : [dd675c9a-1] Mapped to mytest.storage.routes.api$$Lambda$468/0x0000000800426c40@1d14280f
[or-http-epoll-2] reactor.netty.channel.FluxReceive        : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] FluxReceive{pending=0, cancelled=false, inboundDone=false, inboundError=null}: subscribing inbound receiver
[or-http-epoll-2] o.s.core.codec.CharSequenceEncoder       : [dd675c9a-1] Writing "ok123"
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Decreasing pending responses, now 0
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Last HTTP packet was sent, terminating the channel
[or-http-epoll-2] o.s.w.s.adapter.HttpWebHandlerAdapter    : [dd675c9a-1] Completed 200 OK
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Last HTTP response frame
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Dropped HTTP content, since response has been sent already: DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 1505, cap: 1505/1505, unwrapped: PooledUnsafeDirectByteBuf(ridx: 2048, widx: 2048, cap: 2048)), decoderResult: success)
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Dropped HTTP content, since response has been sent already: DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 8192, widx: 32768, cap: 32768)), decoderResult: success)
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Dropped HTTP content, since response has been sent already: DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 16384, widx: 32768, cap: 32768)), decoderResult: success)
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Dropped HTTP content, since response has been sent already: DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 24576, widx: 32768, cap: 32768)), decoderResult: success)
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Dropped HTTP content, since response has been sent already: DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 32768, widx: 32768, cap: 32768)), decoderResult: success)
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Dropped HTTP content, since response has been sent already: DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 8192, widx: 57344, cap: 65536)), decoderResult: success)
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Dropped HTTP content, since response has been sent already: DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 16384, widx: 57344, cap: 65536)), decoderResult: success)
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Dropped HTTP content, since response has been sent already: DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 24576, widx: 57344, cap: 65536)), decoderResult: success)
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Dropped HTTP content, since response has been sent already: DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 32768, widx: 57344, cap: 65536)), decoderResult: success)
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Dropped HTTP content, since response has been sent already: DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 40960, widx: 57344, cap: 65536)), decoderResult: success)
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Dropped HTTP content, since response has been sent already: DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 49152, widx: 57344, cap: 65536)), decoderResult: success)
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Dropped HTTP content, since response has been sent already: DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 8192, cap: 8192/8192, unwrapped: PooledUnsafeDirectByteBuf(ridx: 57344, widx: 57344, cap: 65536)), decoderResult: success)
[or-http-epoll-2] r.n.http.server.HttpServerOperations     : [id: 0xdd675c9a, L:/127.0.0.1:8080 - R:/127.0.0.1:18871] Dropped HTTP content, since response has been sent already: DefaultHttpContent(data: PooledSlicedByteBuf(ridx: 0, widx: 256, cap: 256/256, unwrapped: PooledUnsafeDirectByteBuf(ridx: 256, widx: 256, cap: 65536)), decoderResult: success)

问题找到了,上传的webflux不能自己subscribe,如果直接返回mono就没问题可以打印出数据,原因是为什么暂时还不知道。

1 Like