Search code examples
node.jsmulter

What do the optional limits for Multer mean?


Multer has a couple of optional parameters and I understand some of them. But my understanding is a bit unclear for:

  1. fieldNameSize (is this just the size of field name in req.body or req.file?)
  2. fieldSize (same as (1) but the field value instead?)
  3. fields (is this just other fields in body?)
  4. parts (no idea what this is)
  5. headerPairs (like Bearer auth token header?)

One last thing. Points 3,4 have a limit of infinity by default. Would it be prudent to set some other limit? How do I determine what to set those to prevent DDOS.

Thanks!


Solution

  • The limits object specifies the size limits of the following optional properties:

    • fieldNameSize — maximum field name size. Defaults to 100 bytes
    • fieldSize — maximum field value size. Defaults to 1MB
    • fields — the maximum number of non-file fields. Defaults to Infinity
    • fileSize — maximum file size in bytes. Defaults to Infinity
    • files — maximum of file fields. Defaults to Infinity
    • parts — the maximum number of parts (fields and files). Defaults to Infinity
    • headerPairs — the maximum number of header key-value pairs to parse. Defaults to 2000.

    On how to prevent DDOS, the main setting to focus on would be fileSize. A large file upload would make it very easy to overwhelm your server.

    The rest of the setting is kind of optional, depending on the needs of your project. However, it is a good idea to set to something small like 100 for those that default to infinity.