Add min/max file size limits by mime type.#40
Open
willvincent wants to merge 2 commits intopqina:masterfrom
Open
Add min/max file size limits by mime type.#40willvincent wants to merge 2 commits intopqina:masterfrom
willvincent wants to merge 2 commits intopqina:masterfrom
Conversation
Collaborator
|
Appreciate the PR, will consider for v5 |
chscorpio
reviewed
Jul 10, 2025
| if (mimeMaxFileSizes !== null) { | ||
| Object.keys(mimeMaxFileSizes).forEach(mime => { | ||
| if (file.type === mime || | ||
| (mime.substring(2, -2) === '/*' |
There was a problem hiding this comment.
Suggested change
| (mime.substring(2, -2) === '/*' | |
| (mime.substring(mime.length-2) === '/*' |
chscorpio
reviewed
Jul 10, 2025
| if (mimeMinFileSizes !== null) { | ||
| Object.keys(mimeMinFileSizes).forEach(mime => { | ||
| if (file.type === mime || | ||
| (mime.substring(2, -2) === '/*' |
There was a problem hiding this comment.
Suggested change
| (mime.substring(2, -2) === '/*' | |
| (mime.substring(mime.length-2) === '/*' |
chscorpio
reviewed
Jul 10, 2025
| // Max individual file size in bytes | ||
| maxFileSize: [null, Type.INT], | ||
|
|
||
chscorpio
reviewed
Jul 10, 2025
| // Multipliers should probably be 1024 vs 1000, | ||
| // but this mimics the internal behavior. | ||
| const multiplier = { b: 1, kb: 1000, mb: 1000**2, gb: 1000**3, tb: 1000**4, pb: 1000**5 } | ||
| const num = Number(str.match(/\d/).toString()) |
There was a problem hiding this comment.
Suggested change
| const num = Number(str.match(/\d/).toString()) | |
| const num = Number(str.match(/\d+/).toString()) |
There was a problem hiding this comment.
This works better for values like 1024KB. For example, see the different max sizes in https://community.sinch.com/t5/MMS/What-is-the-maximum-size-of-MMS-message-that-you-can-send/ta-p/7847
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes issue #3.
Adds optional
mimeMinFileSizesandmimeMaxFileSizesconfig options, these should work in conjunction with existing min/max and max total limits, and allow for setting min or max limits by explicit mime type or mime type wildcard group:ie:
That config will allow images of any type up to 3mb, but allow gifs to be up to 5mb, and restrict mp4 videos to 100MB.