magento2: [Magento 2.2.5 - 2.3.x] Upload fails in image uploader
Additional Triage information
- Issue was re-verified on the lates
2.3-develop(16 Oct 2019) for more details see https://github.com/magento/magento2/issues/16531#issuecomment-542557283
Summary When uploading an image in the uploader, the error “File validation failed.” is shown. This error appeared after updating to 2.2.5.
Preconditions PHP Version 7.0.1 Magento ver. 2.2.5 Make function “mime_content_type” undefined
Steps to reproduce
- Edit a block
- Select the image uploader (“Insert Image” button or the one in the editor)
- Select an image from your hd and upload it.
Expected result An added image in the gallery
Actual result An error is shown: “File validation failed.” No image is uploaded.
I tried different kind of filetypes. In 2.2.4 and previous versions there was no problem, the only thing that changed is the updated version.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 8
- Comments: 59 (16 by maintainers)
Same problem here after updating to 2.2.5.
I was able to track my problem to Magento/Framework/File/Uploader.php:
The temporary file name stored in
$this->_file['tmp_name']does not have an extension so Mime type returned will not be correct. I was able to solve my issue by going back and usereturn $this->_file['type'];Please proceed to the Community Forums or the Magento Stack Exchange site for advice or general discussion about this issue. The GitHub issue tracker is intended for Magento Core technical issues only.
I’ve seen this happening as well after upgrading to Magento 2.2.5. But I’ve found the reason. We have a custom module which adds pdf files to the allowed file types to upload, and we’ve defined that like this in the
di.xmlfile of our custom module:But, this now conflicts with Magento 2.2.5 since they’ve changed that xml in the following commit: https://github.com/magento/magento2/commit/2e3d4776a3398900bcdea0b23b7b0dc13e3a0294#diff-998ea63c2adeec7e9a8ecb860ae11db3
So now instead of defining if the file type is allowed or not with a boolean, you have to specify its mime type in the xml file. If the mime type doesn’t match the uploaded file, you’ll get a
File validation failed.error. This is done in: https://github.com/magento/magento2/blob/2.2.5/app/code/Magento/Cms/Model/Wysiwyg/Images/Storage.php#L491-L493If you overwrite those allowed filetypes, and don’t specify the mime type but set it as
1, like Magento did before 2.2.5, then in 2.2.5 it will cause this problem.Further looking into this, it also seems like those default values shouldn’t even be specified again in your custom module, only new filetypes should be specified, because all the file types get merged (default ones + custom module ones). So in our case, I can fix the problem by changing the
di.xmlfile in our custom module as following:@engcom-backlog-pb: it’s arguably if this is a new bug, because the change in the
di.xmlfile was done in a backwards incompatible way I think (not sure how you would do it in a backwards compatible way). But this is debatable.I don’t expect Magento will change or fix this, so people running into this, should just update their custom modules and specify the mime types in the overwritten allowed filetypes list and remove the default ones from there. (I haven’t verified if changing it from a number to a mime type is then still compatible with Magento < 2.2.5, so make sure to double check if your module is installable in various different Magento versions).
enabling Fileinfo php module worked for me
Thanks @DevOli, I had to contact our hosting provider and ask them to check on the Fileinfo PHP module extension which in our case wasn’t enabled. Turning this on resolved the issue for us.
if changing mime type doesn’t work, you can change the return value of the following function.That is the actual function causing this issue.Make sure following function returns true.
Magento/Framework/File/Uploader.php:
Also experiencing this issue on 2.3.2. Some more information; in file upload popup windows in the admin panel, the folder tree on the left side fails to show any files when clicking into any folder. Then you see errors:
I made sure all my permissions were in order.
edit: installing the fileinfo php extension fixed the issue. thx hostep
@mdesplenter, thank you for your report. We’ve acknowledged the issue and added to our backlog.
im getting this error on the category section. On the content tab after selecting my image for the category i get the exact same error on an image that worked in 2.2.4
@madbounce: it’s still an issue as far as I know if you do not have the
fileinfophp extension installed which isn’t a strict requirement for Magento2. A fix is currently being worked on in https://github.com/magento/magento2/pull/24455 (although it doesn’t seem to be going very well)Enabling
fileinfosolved it for us … there should be a check during setup.Yes FileInfo PHP module fixed this for me.
I think the compatibility checker needs to check against the required PHP modules for the version you are about to update to. Not your current version.
This way we’d all be made aware that changes are required prior to upgrade.
@DevOli Thanks That solved the issue for me. @engcom-backlog-pb Really didnt like the way it was declared as not a core issue… but looks like it is. Let me know if u have any solution other than changing in core framework file.
The comment from @hostep fixed my issue. There was indeed a module that allowed pdf’s to be uploaded, and overwriting all allowed files in the new version of Magento. Thank you!
I am facing this issue on Fresh Installation magneto 2.2.5