Open morawskim opened 3 years ago
I guess that this problem is related to the one discussed in #1217
For all, who will find this issue. The problem is not in Filesystem, but in the method getMimeType() of UploadedFile class. Method will return guessed mime type. If you want one, that you defined earlier, in UploadedFile, use getClientMimeType()
issue can be closed...
Bug Report
Summary
The mime type is not correctly passed to the S3 adapter via Flysystem storage class (
\Vich\UploaderBundle\Storage\FlysystemStorage
).Current behavior
symfony/validator
component works well because the image validator can correctly detect file mime type. The problem is with integration betweenvich/uploader-bundle
andleague/flysystem-aws-s3-v3
. When vich tries to store a file in S3 the methoddoUpload
of class\Vich\UploaderBundle\Storage\FlysystemStorage
is called. This method looks like this:In this method, we set option mimetype from file (this is correct because the value will be image/jpg). Because I use an S3 adapter the
write
method of class\League\Flysystem\AwsS3V3\AwsS3V3Adapter
is called. This method is very simple because delegates storing a file to the internal methodupload
. The source code of this method is below:As you can see S3 adapter expects mime type in key
ContentType
instead ofmimetype
. The default implementation ofdetectMimeType
is based on file extension. This is not excatly true (you can check \League\MimeTypeDetection\FinfoMimeTypeDetector::detectMimeType), but this not change a lots.When I want to fetch\check mime type of a file from S3, I get the wrong mime type.
Maybe we could also set key
ContentType
in\Vich\UploaderBundle\Storage\FlysystemStorage::doUpload
? I can prepare PR if you think that this solution is fine.How to reproduce
Configure bundle with FlysystemStorage and S3 adapter (you can use Minio as a free and open-source alternative). Change the file extension from jpg to mp4.
Expected behavior
The correct mime-type should be stored in the file's metadata in S3.