magento2: Product import fails when external image urls are present
Preconditions (*)
- Magento Community 2.3.3 & 2.3-develop
- PHP 7.2.23
Steps to reproduce (*)
- Create a CSV product import file with 2 examples, one has external images (https://example.com/image.jpg), the other locally stored images
- Go to System > Data Transfer > Import and do the following:
- Products (Entity Type)
- Add/Update (Import Behavior)
- Select the csv file to import
- Leave ‘Images File Directory’ empty
- Import the file
Expected result (*)
- Products should be created, and the one having external images should have the image saved as well.
Actual result (*)
- Import fails for products with external images
Reason of failure
After some debugging I found that the default product import path is being set on
Magento\CatalogImportExport\Model\Import\Product:_getUploader()
line 2043 and below.
When running the import, another method is called:
Magento\CatalogImportExport\Model\Import\Uploader:move()
which checks if the file is coming from an URL or from a local path.
Regardless of where the image is coming from, the tmp path is set to the absolute path of the default import image directory <Magento installation>/var/import/images
and the downloaded image is stored in var/tmp
. When checking for the file permission before saving, the path that is checked is <Magento installation>/var/import/images/var/tmp/image_randstring.jpg
, and since the file doesn’t exist in that path, the import fails.
The correct path for the downloaded file should be <Magento installation>/var/tmp/image_randstring.jpg
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 22 (10 by maintainers)
Ran into this issue too on Magento Commerce 2.3.3 Dug a little deeper and think I found the root cause of this issue.
Not sure if I fixed it in the correct way, but this POC patch might help anyone trying to fix this.
external-image-upload.patch.txt
I found another solution. In method:
\Magento\CatalogImportExport\Model\Import\Uploader::_setUploadFile
Change to:
@Nagamaiah007 , this would work with any csv file you try. But anyway, here’s the file (renamed it to txt as github doesn’t allow csv for some reason): export_catalog_product_test_external_image1.txt
local image:
Note that I took these images from google, they’re not my own.