advanced-nova-media-library icon indicating copy to clipboard operation
advanced-nova-media-library copied to clipboard

feat(upload): add option to define desired mime types

Open jdrzejb opened this issue 2 years ago • 1 comments

Hi,

I found this option missing, so decided to create a feature branch for it. Let me know if this can be merged.

jdrzejb avatar May 23 '22 19:05 jdrzejb

There is a validation rule I am using already with laravel media library graphql. 'mimes:jpg,png,pdf' (or can specify full mime type values) https://laravel.com/docs/9.x/validation#rule-mimes

I wonder if the field can parse the rules and extract them if set.

When setting rules, and perhaps if enabled to do so by a config value? Parse rules and extract the mimetypes/file types allowed.

        $rulesValidator = Validator::make([], [$requestAttribute => $this->collectionMediaRules]);
        $mimesRule = $rulesValidator->getRule($this->attribute, 'mimes');
        if (! is_null($mimesRule)) {
            $parameters = $mimesRule[1];
            if ($parameters) {
                // May need to convert ?
                $this->setAllowedMimeTypes($parameters);
                $this->setAllowedFileTypes($parameters)
            }
        }

LiamKarlMitchell avatar Oct 30 '22 00:10 LiamKarlMitchell