You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 between vich/uploader-bundle and league/flysystem-aws-s3-v3.
When vich tries to store a file in S3 the method doUpload 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 method upload. The source code of this method is below:
As you can see S3 adapter expects mime type in key ContentType instead of mimetype.
The default implementation of detectMimeType 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.
The text was updated successfully, but these errors were encountered:
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()
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 between
vich/uploader-bundle
andleague/flysystem-aws-s3-v3
.When vich tries to store a file in S3 the method
doUpload
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 of
detectMimeType
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.
The text was updated successfully, but these errors were encountered: