Handle form containing files and text
See original GitHub issueI have a simple form with a text input and multiple file input.
<form action="/posts" method="post" enctype="multipart/form-data">
<input name="title"/>
<input type="file" name="file" multiple/>
<button>Post</button>
</form>
The problem is that I can’t get the value of "title"
both from ctx.uploadedFiles()
(which understandably returns only files) and from ctx.formParam()
(which stopped returning data when I switched content-type to multipart).
Of course, I can parse the request using FileUpload
directly, but maybe there is already a simpler way to get text values?
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
How to solve <form> that includes file upload and other text ...
You'll need the enctype attribute if you want the file upload to work. FYI, a form can contain every field type, including file...
Read more >Sending form data - Learn web development | MDN
Sending files with HTML forms is a special case. Files are binary data — or considered as such — whereas all other data...
Read more >Handle form containing files and text · Issue #124 - GitHub
I have a simple form with a text input and multiple file input. ... The problem is that I can't get the value...
Read more >How to Use a Simple Form Submit with Files in React
In your App.js file, create a basic form that with a name field and a file input. ... Now, add state in the...
Read more >Forms in HTML documents - W3C
An HTML form is a section of a document containing normal content, markup, special elements called controls (checkboxes, radio buttons, menus, etc.) ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
sorry for the delay, it’s done, will push PR today when i get back to the computer
On Sat, Feb 24, 2018 at 2:03 AM, David notifications@github.com wrote:
I’ll describe how I see these two scenarios from a developer’s point of view.
Upload files: All uploaded files are processed together. E.g. “save all images to the disk”.
Upload both files and text fields: All uploaded files are processed together, text fields are processed separately from files. E.g. “save all images to the disk, extract post title and post text from text fields, write title and text to the database”.
Which means that we need following public “methods”:
Restrictions:
Context#uploadedFiles
orUploadUtil#getUploadedFiles
Context#formParamMap
return parsed multipart form params instead of empty listIf it’s OK to keep things as simple as they are now, I can add
Context#multipartFormFields
(not the best name) which will act similar toUploadUtil#getUploadedFiles
.However, if client code calls “give me all files” and then “give me all text fields”, the form will be parsed twice. If we want to avoid this (and also group the closely related methods together), everything becomes a bit more complicated:
MultipartForm
with two methods:getUploadedFiles : List<UploadedFile>
andgetTextFields : Map<String, Array<String>>
Context#multipartForm : MultipartForm
, which parses the whole form and fillsMultipartForm
with all files and text fieldsHonestly I’m not a fan of both these solutions. The first one looks clunky for me and the second one creates multiple ways to do the same thing.