user2312386
user2312386

Reputation: 121

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

Upvotes: 0

Views: 826

Answers (1)

ant1g
ant1g

Reputation: 1009

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.

Upvotes: 2

Related Questions