plank / laravel-mediable

Laravel-Mediable is a package for easily uploading and attaching media files to models with Laravel
MIT License
758 stars 100 forks source link

SourceAdapter\UploadedFileAdapter bad mime_type from client #324

Closed Surt closed 6 months ago

Surt commented 1 year ago

I was having a problem where some mime_types in files where wrong recognized as text/plain Finally I extended SourceAdapter\UploadedFileAdapter so it uses:

mime_contents_type($this->path()) instead of $this->getClientMimeType($this->source) Now the files are recognized as the correct mime_types

Is there any advice not to rewrite it? Why would I prefer the ClientMimeType? Am I doing it wrong?

frasmage commented 1 year ago

Hi @Surt, apologies for the delay in responding to this, I appear to have missing the notification.

I don't exactly remember what the reasoning was when I first wrote this (~7 years ago now), though I remember looking into the implementations of a number of libraries. Inferring the mime type from the contents does seems more secure (if a little slower) than taking the client's submission at face value.

I am not opposed to changing this to use that approach in the library (PR welcome). You can also register your own adapter in the config which overrides that method.

frasmage commented 6 months ago

I have implemented more explicit handling of client-provided mime types vs. mime type inferred from the file content in the branch for the upcoming major version release