Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multipart form-data example using Undertow

Tags:

java

undertow

I'm trying to upload a text file from a html form.

Is there any example on how to get the text-file from the HttpHandler

like image 444
Vishnu667 Avatar asked Oct 20 '25 11:10

Vishnu667


1 Answers

I once used the following code:

    Builder builder = FormParserFactory.builder();

    final FormDataParser formDataParser = builder.build().createParser(exchange);
    if (formDataParser != null) {
        exchange.startBlocking();
        FormData formData = formDataParser.parseBlocking();

        for (String data : formData) {
            for (FormData.FormValue formValue : formData.get(data)) {
                if (formValue.isFile()) {
                    // process file here: formValue.getFile();
                } 
            }
        }
    }

Based on: http://www.programcreek.com/java-api-examples/index.php?api=io.undertow.server.handlers.form.FormData

like image 151
mkobel Avatar answered Oct 22 '25 00:10

mkobel