It is possible defined file size by file type in mediamanager?

Hi,

how would I define the upload file size limitation by type in mediamanager or mediamanager form widget?

Image (png, jpg): 1MB
PDF: 5MB

I don’t mean the file upload form widget

Hey @mcore

The media manager’s configuration is found in config/media.php. It does not currently have a maximum file size configuration, but it may do so in the future.

Hey @daft

i figured it out in plugin boot method run the event

 Event::listen('media.file.beforeUpload', function ($widget, $uploadedFile) {

            $fileSize = $uploadedFile->getSize() / 1024;
            $mimeType = $uploadedFile->getMimeType();

            $maxImageSize = 1000; // 1 MB
            $maxPdfSize = 5000;   // 5 MB

            $imageMimeTypes = [
                'image/jpeg',
                'image/png',
                'image/gif',
                'image/bmp',
                'image/webp'
            ];

            if (in_array($mimeType, $imageMimeTypes)) {
                if ($fileSize > $maxImageSize) {
                    throw new ApplicationException('The uploaded image is too large! Maximum size is 1 MB.');
                }
            } elseif ($mimeType === 'application/pdf') {
                if ($fileSize > $maxPdfSize) {
                    throw new ApplicationException('The uploaded PDF is too large! Maximum size is 5 MB.');
                }
            }
        });
2 Likes