Skip to content

Conversation

@willvincent
Copy link

Closes issue #3.

Adds optional mimeMinFileSizes and mimeMaxFileSizes config 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:

<script>
        // Register the plugin with FilePond
        FilePond.registerPlugin(FilePondPluginFileValidateSize);

        // Get a reference to the file input element
        const inputElement = document.querySelector('input[type="file"]');

        // Create the FilePond instance
        const pond = FilePond.create(inputElement, {
            mimeMaxFileSizes: {
                'image/*': '3MB',
                'image/gif': '5MB',
                'video/mp4': '100MB'
            }
        });
</script>

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.

@rikschennink
Copy link
Collaborator

Appreciate the PR, will consider for v5

if (mimeMaxFileSizes !== null) {
Object.keys(mimeMaxFileSizes).forEach(mime => {
if (file.type === mime ||
(mime.substring(2, -2) === '/*'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(mime.substring(2, -2) === '/*'
(mime.substring(mime.length-2) === '/*'

if (mimeMinFileSizes !== null) {
Object.keys(mimeMinFileSizes).forEach(mime => {
if (file.type === mime ||
(mime.substring(2, -2) === '/*'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
(mime.substring(2, -2) === '/*'
(mime.substring(mime.length-2) === '/*'

// Max individual file size in bytes
maxFileSize: [null, Type.INT],

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

// 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())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const num = Number(str.match(/\d/).toString())
const num = Number(str.match(/\d+/).toString())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants