Magento – Magento2 Product import (image filenames)

importmagento2productproduct-images

I'm not sure that this is a bug, as it's intentional from the looks of it, but …

I'm working on a migration from Zencart and the original site's media folder has been downloaded and we've written a custom importer.

The feedback from the product importer is very generic, but it turns out that the original media including a space in it's filename is an issue.

Specifically, the PATH_REGEXP within \Magento\CatalogImportExport\Model\Import\Product\Validator\Media.php doesn't allow for this.

Is there any reason for this restriction? Is this due to how different file systems may interpret special characters? If I alter the REGEX to allow for spaces, Magento2 parses the file successfully, and actually changes the filename to a more comfortable format (underscores instead of spaces)

Steps to reproduce

  1. Create product import
  2. Ensure image reference within base_image, small_image or thumbnail_image contains a space
  3. Place files within pub/media/images/

Expected result

  1. Media images pass validation

Actual result

  1. Media Images do not pass validation

  2. Wrong URL/path used for attribute image in row(s): 2, 3, 4, 5, 6, 7, 8, 10, 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49

  3. Wrong URL/path used for attribute small_image in row(s): 2, 3, 4, 5, 6, 7, 8, 10, 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49
  4. Wrong URL/path used for attribute thumbnail in row(s): 2, 3, 4, 5, 6, 7, 8, 10, 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49

Best Answer

I've also recently encountered this on M2.2.2

After some investigation, I personally believe this is a feature as opposed to a bug as the Magento team appear validating image names as web safe i.e. no spaces or special characters.

Historically when working with M1.x (little/no image name validation) I spent many hours fixing images when clients tried to upload images which were not web safe, so I'm welcoming this validation with open arms.

Related Topic