gpt4 book ai didi

java - 多部分文件上传表单数据附件为空

转载 作者:行者123 更新时间:2023-12-02 11:28:13 25 4
gpt4 key购买 nike

我正在使用 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);

最佳答案

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

Handler h = new EagerFormParsingHandler(yourHandler);

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

关于java - 多部分文件上传表单数据附件为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49464775/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com