question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Different file size limitation based on file type

See original GitHub issue

I have an endpoint to upload files. I would like to have different file size limits depending on the file type. Images size limit =< .5 MB and PDF size limit =< 2MB.

The limits.fileSize options only allows for one value, and I can’t do it in the fileFilter property either… So how could I do it?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

7reactions
LinusUcommented, Mar 14, 2018

I think you should be able to do it with the fileFilter property?

function fileFilter (req, file, cb) {
  if (file.mimetype === 'application/pdf' && file. size > 2 * 1014 * 1024) {
    return cb(new Error('File too large'))
  }

  cb(null, true)
}
1reaction
msteini82commented, Aug 27, 2019

Hi @LinusU

I have the same problem on Multer 1.4.2. I need to limit the file size on base of the file type for my project. It would be really nice, if that would be possible inside the file filter function.

Or can you expect when there will be a stable release for Multer 2.0?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set different max upload size limits based on file type/extension
I'm asking for a way to have multiple limits for the Max upload file size field based on the uploaded file extension. Thank...
Read more >
Maximum File Size - an overview | ScienceDirect Topics
As designed, the maximum NTFS file size is 16 EB (16 × 1024 6 or 2 64 bytes). As implemented, the maximum NTFS...
Read more >
Allowed File Types and File Size Limits - Princeton Site Builder
Depending on the the type of file you are uploading there are different file size limits and file type restrictions. Document: 30 MB...
Read more >
File size - Wikipedia
Typically, file size is expressed in units of measurement based on the byte. By convention, file size units use either a metric prefix...
Read more >
Restrictions and limitations in OneDrive and SharePoint
Limitations · File upload and download sizes · File name and path lengths · Thumbnails and previews · Number of items that can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found