mscdex / busboy

A streaming parser for HTML form data for node.js
MIT License
2.84k stars 213 forks source link

Allow passing function to limits.fileSize #317

Closed hossein-zare closed 2 years ago

hossein-zare commented 2 years ago
limits: {
  fileSize: (req) => {
    return req.storage.maxFileSize;
  }
}
mscdex commented 2 years ago

Why?

hossein-zare commented 2 years ago

I'm using multer which is written on top of this package. Users have their own storage data like maxFileSize and it's not hard-coded and the same for everyone.

Example: Bill's maxFileSize is 1,048,576 Bytes and Alice's is 3,145,728 Bytes.

const upload = multer({
    storage,
    limits: {
        fileSize: (req) => {
            return req.storage.maxFileSize;
        },
    },
});
charmander commented 2 years ago

Seems like that feature makes more sense for multer’s API (declarative middleware) than busboy’s (single-use object constructed based on the request).

mscdex commented 2 years ago

I agree, I don't think busboy is the right place to implement this sort of feature. What you're asking for should be able to be trivially implemented by just setting limits dynamically (when calling multer()) based on data hanging off of req.

hossein-zare commented 2 years ago

Alright, I hope multer won't send me back to busboy 😁