E
E
Egor Petrov2018-10-24 12:38:14
Node.js
Egor Petrov, 2018-10-24 12:38:14

How to set a limit on the uploaded file (different limits for different routes)?

Sobsna, the question is in the title, I use the express-fileupload, body-parser packages.
I tried to set it like this, in general for all routes:

  • app.use(bodyParser.json({limit: 2 * 1024 * 1024, extended: true}));
  • app.use(fileUpload({limits: { fileSize: 2 * 1024 * 1024 }}));

Doesn't work, large files still upload.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Skibin, 2018-10-24
@chel1

body-parser does not control file uploads (multipart), so the restriction will affect only data
express-fileupload uses the busboy parser, the limits for which actually limit file recognition to the size you specified. Those. will be loaded, but will not be parsed.
To limit the loading of the POST body, use nginx as a limiter, and nodejs as a handler only.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question