After looking at this article: http://lollyrock.com/articles/express4-file-upload/
I've realized that Multer used to allow file uploads when you did not know the name of the form field being uploaded. For example, if you look at the "using Multer" section of the article, you'll see that the writer does not use either .single()
, .array()
, or .fields()
when calling app.use()
. If you do that with the current version of Multer, you'll get the error TypeError: app.use() requires middleware functions
.
While I have a slight idea as of how to use .single()
, .array()
, or .fields()
, my current project requires that I send an unspecific amount of files to my server (may be a series of .png
or .log
files). Therefore, I don't know what the field names will be beforehand.
Doing that was easy with the version of Multer used in the article (0.1.6), but seems impossible when attempting it in the current version of Multer (1.0.3) since you need to specify the form fieldnames.
Alternatively, finding a full guide of Multer online has been a challenge, since the best one seems to be the Readme of the GitHub repo, and that one seems to be lacking. Maybe the answers that I'm looking for will be in a guide somewhere.
Thank you!
multer().array('foo')
then you can have as many files as you want, as long as the field name for each file is the same (foo
). Surely requiring that the client uses the same field name for each file is not out of the question? – Analisaanalise.any()
method I would prefer to leave that out. It seems like the way that @Analisaanalise proposed is the way to go. Is there some reason why that would not work for you? – Entente