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

Add multipart/form-data support #88

Open
dougwilson opened this issue Mar 29, 2015 · 27 comments
Open

Add multipart/form-data support #88

dougwilson opened this issue Mar 29, 2015 · 27 comments

Comments

@dougwilson
Copy link
Contributor

This is just such a basic type of the web, it's hard to keep ignoring it. Because of the pattern of this module, though, we really cannot support files. But I don't see why we can support it, but just drop files. Thoughts?

@reecefenwick
Copy link

As someone who doesn't use multipart form data requests, I can still see the value in it.

It probably makes sense for this module to be able to parse multipart forms.

But is there a need? Are people happy to bring in an extra library to handle it (e.g busboy)?

@dougwilson
Copy link
Contributor Author

People don't ever seem to be happy :)

@Fishrock123
Copy link
Contributor

Ahh form-data

It probably makes sense for this module to be able to parse multipart forms.

Yes, this would be nice. :)

@julien51

This comment has been minimized.

@macmichael01
Copy link

Yes this is a highly needed feature. :)

Basically the body parsing options are:

  1. field inputs - Works good.
  2. file inputs - need something else
  3. file and field inputs - need something else as body parser does not know how to process fields when enctype is set to multipart.

@macmichael01
Copy link

What can we do to gain some traction on this issue? Would someone like to collaborate on implementing this?

@dougwilson
Copy link
Contributor Author

Hi @macmichael01 so you are interested in a parser that would drop the files, then?

@macmichael01
Copy link

"a parser that would drop the files" - That would be a nice work around for now. Full file upload support would be even better. I'm guessing that are some security obstacles.

@dougwilson
Copy link
Contributor Author

@macmichael01 , this module will never have full file upload, as it does not fit into the fundamental design. You'll always have to reach for the modules listed in the readme for parsing with file support.

@macmichael01
Copy link

@dougwilson That's fine. Should I open a new ticket for suggestion that you made?

@dougwilson

This comment has been minimized.

@dougwilson dougwilson self-assigned this Oct 13, 2015
@macmichael01

This comment has been minimized.

@dougwilson

This comment has been minimized.

@macmichael01

This comment has been minimized.

@dougwilson

This comment has been minimized.

@macmichael01

This comment has been minimized.

@macmichael01

This comment has been minimized.

@franciscolourenco
Copy link

+1 for this, specially since XMLHttpRequest 2 now supports FormData()

Currently using multer just for this purpose. This way it doesn't accept any files, but doesn't look very pretty:

formdataParser = require('multer')().fields([])
app.use(formdataParser)

@0x70b1a5

This comment has been minimized.

@dougwilson
Copy link
Contributor Author

Hi @0x70b1a5 it was my impression from the conversation above that a PR would have been coming, but none ever materialized. You're absolutely welcome to tackle this based on the implementation discussed above. The issue is open so people are aware that it is something they could work on and contribute towards if they are so inclined to do so. I personally simply use the multipart parsers listed in the README directly and don't have any issues accepting multipart data; the issue was opened because I kept closing the requests for this, so this would be the tracking request. If I closed this, I'm sure new issues will start popping up just like they used to. If you have a better solution, please let me know.

@hjs-robin

This comment has been minimized.

@chrisdothtml
Copy link

For anyone else stumbling across this issue, express-form-data does the job pretty well

@chrisdothtml
Copy link

@reecefenwick

Are people happy to bring in an extra library to handle it (e.g busboy)?

I think the main annoyance is that we already are bringing in an extra library (in addition to express) to parse our body (body-parser). Having to bring yet another library in because the body parser doesn't support all types of bodies is a pain

@abinhho
Copy link

abinhho commented Mar 31, 2020

If we uses serverless and a node server like NestJs. The request body will be converted to Buffer and forward to nodejs server, if we don't have multipart parser, we can not read the file upload.

@expressjs expressjs deleted a comment from ajbraus Mar 31, 2020
@Deshanm123

This comment was marked as spam.

@jimmywarting
Copy link

jimmywarting commented May 13, 2023

simple dependency free workaround:

app.post('/upload', async (req, res) => {
  const formData = await new Response(req, { headers: req.headers }).formData()
  const files = formData.getAll('files')
})

(require NodeJS v18+)

@dresende
Copy link

use Formidable to handle "multipart/form-data".

This worked for me. I already did it for uploads, I just had to put it always on base route and not just uploads. No other change needed.

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

No branches or pull requests