Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

gianlucaz's avatar

Spatie Laravel-medialibrary Pro mime type issues

Hello,

for a 3D application I am trying to upload files with the ending .stl and .constructioninfo. The first one is a 3D format and the second one is basically a XML file.

I am using Medialibrary PRO with Vue3.

When I do not define any validation rules I get a 422 and this error.

{"errors": "The file field must be a file of type: 7z, aiff, asc, asf, avi, avif, bmp, cap, cin, csv, dfxp, doc, docx, dotm, dotx, fla, flv, gif, gz, gzip, itt, jp2, jpeg, jpg, jpx, js, json, lrc, m2t, m4a, m4v, mcc, mid, mov, mp3, mp4, mpc, mpeg, mpg, mpsub, ods, odt, ogg, ogv, pdf, png, potx, pps, ppsm, ppsx, ppt, pptm, pptx, ppz, pxd, qt, ram, rar, rm, rmi, rmvb, rt, rtf, sami, sbv, scc, sdc, sitd, smi, srt, stl, sub, svg, swf, sxc, sxw, tar, tds, tgz, tif, tiff, ttml, txt, vob, vsd, vtt, wav, webm, webp, wma, wmv, xls, xlsx, zip."}

It's interesting to note that .stl is mentioned in the list of valid file types.

When I try to set up validation rules like this:

validation-rules="{accept: ['application/x-navistyle','application/vnd.ms-pki.stl', 'application/octet-stream', 'application/stl', 'application/sla', 'model/stl', 'model/x.stl-binary']}"

I can only drag and drop files into the upload area. The file selector doesn't display any files when I click the "+" icon. And I receive this error message:

File type not allowed application/x-navistyle, application/vnd.ms-pki.stl, application/octet-stream, application/stl, application/sla, model/stl, model/x.stl-binary STL

This issue occurs even with temporary uploads (S3).

Can anyone help? Your assistance would be greatly appreciated. Thank you!

  • Laravel 10

  • spatie/laravel-medialibrary 10.14.0

  • spatie/laravel-medialibrary-pro 2.7.3

  • S3 filesystem

0 likes
2 replies
LaryAI's avatar
Level 58

The issue you are facing is related to the validation rules for file uploads in the Spatie Laravel-medialibrary package. The error message suggests that the file type you are trying to upload is not allowed.

To resolve this issue, you need to update the validation rules to include the file types you want to allow. In your case, you want to allow files with the extensions ".stl" and ".constructioninfo".

Here's an example of how you can update the validation rules:

use Spatie\MediaLibrary\MediaCollections\Models\Media;

Media::addMediaValidationRules(function () {
    return [
        'file' => 'mimetypes:application/x-navistyle,application/vnd.ms-pki.stl,application/octet-stream,application/stl,application/sla,model/stl,model/x.stl-binary',
        // Add more mimetypes if needed
    ];
});

Make sure to add this code in a suitable place, such as a service provider or a dedicated file for media library configuration.

This code adds a custom validation rule using the mimetypes rule provided by Laravel. It specifies the allowed mimetypes for the file upload. You can add more mimetypes if needed.

After updating the validation rules, you should be able to upload files with the extensions ".stl" and ".constructioninfo" without any issues.

Note: If you are using temporary uploads with S3, make sure to update the validation rules on the server-side as well.

Let me know if you have any further questions!

gianlucaz's avatar

I quote:

"Note: If you are using temporary uploads with S3, make sure to update the validation rules on the server-side as well."

Where would be that place or file to add the validation rules server side? I did not find any suitable and existing file yet.

Please or to participate in this conversation.