Skip to content

Adding product image: File doesn't exist #21978

@WalterSmulders

Description

@WalterSmulders

Preconditions (*)

  1. Magento 2.2.8 & 2.3.1

Steps to reproduce (*)

  1. Add image trough \Magento\Catalog\Model\Product\Gallery\Processor->addImage
  2. With $product, relative path, $options and true, false

Expected result (*)

  1. Image should be added to the product

Actual result (*)

  1. Exception will be raised:
    [InvalidArgumentException]
    File 'pub/media/import/' doesn't exist

I blocked out the prefix and suffix to the file location but these are correct. The error is because of the following:

In file: Magento\Catalog\Model\Product\Gallery\Processor
Function: addImage
Lines: 194, 195, 196

With "$absoluteFilePath = $this->mediaDirectory->getAbsolutePath($file);" the absolute path to the file in pub/media/import will be resolved. In theory this is correct. However the lines 175 till 190 can possibly move the image to a other directory. When this happens $absoluteFilePath will be filled with a path that is the old path before the move was done since it uses the variable $file. Thus resulting on $this->mime->getMimeType($absoluteFilePath); giving an exception that the file doesn't exist anymore.

Possible fix is by moving lines 194, 195, 196 to above line 175 so the checks are done before the file will be moved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Component: CatalogFixed in 2.2.xThe issue has been fixed in 2.2 release lineFixed in 2.3.xThe issue has been fixed in 2.3 release lineIssue: Clear DescriptionGate 2 Passed. Manual verification of the issue description passedIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedIssue: Format is validGate 1 Passed. Automatic verification of issue format passedIssue: Ready for WorkGate 4. Acknowledged. Issue is added to backlog and ready for developmentProgress: PR CreatedIndicates that Pull Request has been created to fix issueReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions