【问题标题】:Multipart Fileupload Formdata attachment is nullMultipart Fileupload Formdata 附件为空
【发布时间】:2018-03-24 12:39:12
【问题描述】:

我正在使用一个 swagger 生成的 undertow 服务器 (light4j),并试图通过 html 表单实现文件上传。 问题是应该包含文件的 Formdata 为空。 代码很简单,这可能是什么问题? 我发现的示例正好显示了此代码,可能已注册为处理程序,但这不应影响功能。还有什么要考虑的吗?

前端

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

【问题讨论】:

    标签: java forms swagger multipart undertow


    【解决方案1】:

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

    Handler h = new EagerFormParsingHandler(yourHandler);
    

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

    【讨论】:

      猜你喜欢
      • 2017-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-20
      相关资源
      最近更新 更多