简体   繁体   中英

Multipart Fileupload Formdata attachment is null

Im using a swagger-generated undertow server (light4j) and am trying to achieve a fileupload via html form. Problem is that the Formdata, which is supposed to have the file in it, is null. Code is very simple, what could be the issue here? The examples i found show exactly this code, maybe registered as handler, but this should not affect the functionality. is there anything else to consider?

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>

Backend

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

You need to tell undertow to parse the form data. For that you can use the handler EagerFormParsingHandler , as follows:

Handler h = new EagerFormParsingHandler(yourHandler);

And then indeed, in your handler you retrieve the FormData attachment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM