10

I know there are something like multiparty, and busboy and formidable. I want to know is there any chance to upload files without them.

lpy
  • 567
  • 1
  • 6
  • 19
  • 1
    You might want to include the reasoning for not wanting to use such libraries. – mscdex May 18 '14 at 02:42
  • @mscdex They are good, and easy to use, I just want to know some ways without them. – lpy May 18 '14 at 02:50
  • could anyone help me with the problem? https://stackoverflow.com/questions/63315209/how-to-cascade-a-file-uploaded-in-react-to-node-js-and-then-to-another-api-all many thanks. – Suresh Kumar Aug 10 '20 at 10:25

3 Answers3

15

If you want to upload files you need to be able to parse multipart content. You can either use to parse it or implement your own. Here's a list the modules that can help you:

Direct parsing (in descending popularity based on Github stars as of Nov 2016):

Middleware:

Both:

  • parted - last commit Jan 2015

If you want to write your own parser, you can have a look how above modules does it. Check these links also:

Happy coding.

Community
  • 1
  • 1
Farid Nouri Neshat
  • 26,357
  • 6
  • 67
  • 109
  • Top modules for direct parsing as of Nov 2016: node-formidable (3376 stars), busboy (814 stars), node-multiparty (557 stars). multer is middleware built on busboy, and is much more popular than the busboy or multiparty middleware listed. parted hasn't been updated in two years. – Simon D Nov 27 '16 at 15:54
  • Updated! Thanks – Simon D Nov 27 '16 at 16:00
  • what's the pros and cons of using direct-parser vs. middleware? – Jeb50 Jun 09 '19 at 23:02
  • 1
    Middlewares are direct-parsers wrapped to be a middleware. It's easier to use a middleware. – Farid Nouri Neshat Jun 11 '19 at 06:32
1

Without them, parsing multipart forms can be hard to do right and efficiently. Unless you really want to go through that work of parsing multipart yourself (urlencoded forms are much easier), you really should stick to using one of connect-multiparty, multer, connect-busboy, reformed, etc.

mscdex
  • 93,083
  • 13
  • 170
  • 135
0

Standalone parsers like busboy can be used with or without Express.js. On the other hand Express.js middlewares augment the request object by adding req.files that you can conveniently access the files. Some implementations store intermediate files either in temp directory or in memory. Others let you access stream of uploaded file contents without busting the server's memory or hard disk.

It's possible to implement parsing multipart/form-data HTTP request yourself and it's a fine programming exercise. However, if development time, maintainability and bug fixes are of concern, then ready-made libraries come in handy.

Depending on your situation, ask these questions in order to determine which library suits you best.

  • is saving intermediate files ok, or do you want to stream the files?
  • if saving intermediate files is alright, would you prefer them in memory or on hard disk?

Then pick one from the list of most used file upload processing libraries. The decision tree is from the article:

Choose between Formidable, Busboy, Multer and Multiparty for processing file uploads

Choose between Formidable, Busboy, Multer and Multiparty for processing file uploads

pspi
  • 9,153
  • 1
  • 12
  • 13