Multipart FileUpload FormData附件为空



im使用Swagger-Interated Undertow服务器(Light4J(,并试图通过HTML表单实现FileUpload。问题在于,应该在其中包含文件的FormData为null。代码非常简单,这里可能是什么问题?我发现的示例完全显示了此代码,也许已注册为处理程序,但这不应影响功能。还有其他要考虑的吗?

frontend

<form action="http://localhost:8081/edit/upload" method="post" enctype="multipart/form-data"> <input type="file" name="upfile" id="upfile"> <input type="submit" value="Upload"> </form>

后端

@Override public void handleRequest(HttpServerExchange exchange) throws Exception { //following attachment is null! FormData attachment = exchange.getAttachment(FormDataParser.FORM_DATA);

您需要告诉 proctderow 以解析表单数据。为此,您可以使用处理程序EagerFormParsingHandler,如下:

Handler h = new EagerFormParsingHandler(yourHandler);

,然后确实,在您的处理程序中您检索FormData附件。

最新更新