我已经看到了reactor-netty的例子,关于如何使用多部分表单(https://github.com/reactor/reactor-netty/blob/89796a1839a1439a1800424e130515357a827392/src/test/java/reactor/netty/http/client/HttpClientTest.java#L337)发布文件
但是我找不到任何关于如何使用reactor-netty编写可以解析多部分信息的服务器的信息。
看起来netty可以使用HttpPostRequestDecoder类来做这件事,但我看不出它适合在哪里……
我还看到InterfaceHttpData是Attributes和FileUpload的母类,但我不知道从哪里可以从请求中获得这些对象……
有没有人这样做过?有什么线索吗?
非常感谢
发布于 2019-07-03 18:13:33
request.receive()
.aggregate()
.flatMap(byteBuf -> {
FullHttpRequest dhr = new DefaultFullHttpRequest(request.version(), request.method(), request.uri(), byteBuf, request.requestHeaders(), EmptyHttpHeaders.INSTANCE);
HttpPostRequestDecoder postDecoder = new HttpPostRequestDecoder(new DefaultHttpDataFactory(false), dhr, CharsetUtil.UTF_8);
// loop data
for (InterfaceHttpData data : postDecoder.getBodyHttpDatas()) {
// attribute
if (data.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) {
// (MemoryAttribute) data
}
// upload
else if (data.getHttpDataType() == InterfaceHttpData.HttpDataType.FileUpload) {
// (MemoryFileUpload) data
}
}
postDecoder.destroy();
dhr.release();
});https://stackoverflow.com/questions/55917790
复制相似问题