skip to Main Content

When I import product data or I upload image directly to a product I get the following message (was not uploaded. Filename is too long; must be 90 characters or less)

Recently my magento has been updated and I didn’t have this problem before.

Does anyone know how I can increase the number of characters slightly?

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    I was able to solve the problem myself.

    The file in question is located in the following folder vendormagentoframeworkFile Uploader.php

    search for the following code:

    // account for excessively long filenames that cannot be stored completely in database
    if (strlen($fileInfo['basename']) > 90) {
        throw new InvalidArgumentException('Filename is too long; must be 90 characters or less');
    

    Adjusting this file is not the best method, I have to add


  2. For anyone finding this question on Google, I wanted to share additional findings, as I’ve faced the same issue. Perhaps you will find them helpful.

    As @Timo already wrote, the limit of 90 characters is hard-coded in the getCorrectFileName() method in vendormagentoframeworkFileUploader.php (in older versions of Magento).

        public static function getCorrectFileName($fileName)
        {
    
            (...)
    
            $maxFilenameLength = 90;
    
            if (strlen($fileInfo['basename']) > $maxFilenameLength) {
                throw new LengthException(
                    __('Filename is too long; must be %1 characters or less', $maxFilenameLength)
                );
            }
    
            (...)
    
        }
    

    Since this method is static, writing a plugin is not possible and apparently providing a preference won’t work as well.

    It seems that there was a fix for this already available in Magento, but only in versions 2.4.2 and 2.4.2-p1. Then, for whatever reasons it got removed. See the related Github issue.

    Since Magento v2.4.5 the file name length is now limited to 255 characters:

        private const MAX_FILE_NAME_LENGTH = 255;
    
        (...)
    
        public static function getCorrectFileName($fileName)
        {
    
            (...)
    
            if (strlen($fileInfo['basename'] ?? '') > self::MAX_FILE_NAME_LENGTH) {
                throw new LengthException(
                    __('Filename is too long; must be %1 characters or less', self::MAX_FILE_NAME_LENGTH)
                );
            }
    
            (...)
    
        }
    

    So, until you upgrade your Magento version to 2.4.5 or newer, it seems that making a change in the core code is the only option, either manually or using a composer patch.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search