Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MultipartDataHandler missing fields while mapping #244

Open
kkrvorq opened this issue Oct 31, 2022 · 1 comment
Open

MultipartDataHandler missing fields while mapping #244

kkrvorq opened this issue Oct 31, 2022 · 1 comment

Comments

@kkrvorq
Copy link

kkrvorq commented Oct 31, 2022

My front end is in svelte; Just created a very simple form with enctype="multipart/form-data" and is as -

(Just for simplicity, I ignored file input)

        <form method="POST" enctype="multipart/form-data">
            <fieldset>
                <label for="name">Name</label>
                <input type="text" name="name" id="name">
                <label for="type">Type</label>
                <input type="text" name="type" id="type">
                <label for="description">Description</label>
                <input type="text" name="description" id="description">
                <input type="submit" value="Submit">
            </fieldset>
        </form>

I use the following line to map the form data fields into map -

 HashMap<String, String> fields = new HashMap<String, String>();
 request.handleMultipart(MultipartDecoder.MultipartDataHandler.fieldsToMap(fields));

But, not all the 3 inputs in the html form is received in fields HashMap. I got only 2 fields mapped.

Logs is as follows -

20:10:27.869 ERROR servlet.CRUDServlet - --- Enter POST Request ---
20:10:27.871 ERROR servlet.CRUDServlet - Headers : [Accept-Language=, sec-fetch-mode=cors, Accept-Encoding=gzip, deflate, Content-Type=multipart/form-data; boundary=----formdata-undici-0.3572468109466933, Connection=keep-alive, Accept=/*, Transfer-Encoding=chunked, User-Agent=undici, Host=localhost:8080]
20:10:27.872 ERROR servlet.CRUDServlet - Path parameters : {}
20:10:27.872 ERROR servlet.CRUDServlet - Query parameters : {}
20:10:27.872 ERROR servlet.CRUDServlet - Post parameters : {}
20:10:27.873 ERROR servlet.CRUDServlet - Contains MultipartData? : true
20:10:27.873 ERROR servlet.CRUDServlet - Body as String : ------formdata-undici-0.3572468109466933
Content-Disposition: form-data; name="name"

Container1
------formdata-undici-0.3572468109466933
Content-Disposition: form-data; name="type"

Private
------formdata-undici-0.3572468109466933
Content-Disposition: form-data; name="description"

Abcdefg
------formdata-undici-0.3572468109466933--
Mapped fields: {name=Container1, type=Private}
Mapped fields size: 2
20:10:27.909 ERROR servlet.CRUDServlet - --- Exit POST Request ---

@eduard-vasinskyi
Copy link
Contributor

Hi, @kkrprodev

I have tried adding your <form> to a new HTML page with an action attribute pointing to some AsynServlet that decodes multipart data. A servlet seems to work fine (3 fields received). I have also tried to manually decode the request body from your logs using MultipartDecoder and still got 3 fields.

Maybe the problem arises when Svelte is introduced? Could you please create a simple demo project that illustrates the problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants