Multer: do I have to specify field name in upload.fields?

Created on 13 Feb 2017  Â·  4Comments  Â·  Source: expressjs/multer

I want to upload multiple files with random field name

curl http://localhost:5050/upload \
     -X POST \
     [email protected] \
     [email protected] \
     [email protected]

When I don't specify "a", "b" and "c" in upload.fields, I will get "Error: Unexpected field".

Note that the field name is random and the number of fields can not be determined. So it is impossible to define field name in upload.fields.

Do I have to specify field name? How can I solve this problem?

Most helpful comment

You can use .any(), be sure to handle all the files though :)

https://github.com/expressjs/multer#any

All 4 comments

You can use .any(), be sure to handle all the files though :)

https://github.com/expressjs/multer#any

Works like a charm! Thank you!

I had the exact same problem using multer to parse incoming emails with attachments. using .any solved the problem. Thank you.

In case you just copied that curl command and wonder why it doesn't work — it's missing -F switch.

Was this page helpful?
0 / 5 - 0 ratings