Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Post image upload is not working #600

Open
gfrancisco-sh opened this issue Aug 28, 2024 · 1 comment
Open

Post image upload is not working #600

gfrancisco-sh opened this issue Aug 28, 2024 · 1 comment

Comments

@gfrancisco-sh
Copy link

gfrancisco-sh commented Aug 28, 2024

Describe the bug
It's not possible to upload image using upload button in admin.
image

Preconditions:

  • Magento Version: 2.4.5-p7
  • Module Version: 2.11.6
  • PHP Version: 8.1

To Reproduce
Steps to reproduce the behavior:

  1. Go to Magefan -> Posts page and add or edit any post.
  2. Click on Upload button inside Display settings section
  3. Select a valid image (png, jpg)
  4. See error

Expected behavior
Image is uploaded and visible when saved

Actual behavior
Error message is shown: File validation failed

Screenshots
image

Additional context
I did a research about the issue and the problem is the \Magefan\Blog\Model\ImageUploader class is overriding \Magento\Catalog\Model\ImageUploader but is missing two variables in constructor (only $allowedMimeTypes is relevant for this isse)

to fix, I changed the constructor like this:

public function __construct(
        \Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase,
        \Magento\Framework\Filesystem $filesystem,
        \Magento\MediaStorage\Model\File\UploaderFactory $uploaderFactory,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Psr\Log\LoggerInterface $logger,
        $baseTmpPath,
        $basePath,
        $allowedExtensions,
        array $allowedMimeTypes = [], //added missing variable
        Name $fileNameLookup = null //added missing variable
    ) {
        parent::__construct(
            $coreFileStorageDatabase,
            $filesystem,
            $uploaderFactory,
            $storeManager,
            $logger,
            $baseTmpPath,
            $basePath,
            $allowedExtensions,
            $allowedMimeTypes, //added to parent class constructor
            $fileNameLookup //added to parent class constructor
        );
        $this->filesystem = $filesystem;
    }

Then, I added the allowed mime types in di for this class:

<type name="Magefan\Blog\Model\ImageUploader">
        <arguments>
            <argument name="allowedMimeTypes" xsi:type="array">
                <item name="jpg" xsi:type="string">image/jpg</item>
                <item name="jpeg" xsi:type="string">image/jpeg</item>
                <item name="gif" xsi:type="string">image/gif</item>
                <item name="png" xsi:type="string">image/png</item>
            </argument>
        </arguments>
    </type>
@magefan
Copy link
Owner

magefan commented Sep 16, 2024

@gfrancisco-sh thank you for your report. Unfortunatly we cannot reproduce the issue. It should work without allowedMimeTypes .
If we don't set it it is an empty array https://github.com/magento/magento2/blob/2.4.5-p7/app/code/Magento/Catalog/Model/ImageUploader.php#L99

Then this empty array is passed to the validation
https://github.com/magento/magento2/blob/2.4.5-p7/app/code/Magento/Catalog/Model/ImageUploader.php#L248

And if array is empty checkMimeType it returns true

Maybe you have some third-party extension that modifies allowedMimeTypes for Magefan\Blog\Model\ImageUploader ? Or Magento\Catalog\Model\ImageUploader

The problem that we cannot add allowedMimeTypes to our extension yet, as we currently still provide support for Magento 2.3.0 which does not have this property. Once we stop supporting it we will be able to add this modification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants