Akeneo – Import Images & Files with CSV

Import Example

It is possible to import Images and Files through a CSV file.

To do so you have to upload the new images and files to the server in the same folder where the CSV file is located.

For example we want to add the example.jpg image to the product with SKU `testproduct` so we create the following CSV file:

sku;image1
testproduct;example.jpg

Now upload the CSV file and the example.jpg image to the server for example to the app/custom-import folder.

Once the files are uploaded create an import profile and set the `File path` within the `Properties` of the profile to the CSV file with the full path.

In this example the path is `/var/www/app/custom-import/test.csv`.

Now you are ready to run the import.

Overwrite existing images

If you have existing images in Akeneo and you want to overwrite them make sure you first import a CSV file with only the SKU column filled in because if you import a file with the same name as the existing one the image or file won’t be updated.

Retrieve Magento 1 Product Files

It is possible to create the CSV file based on the Magento 1 Data so you can migrate the files to Akeneo when you are going to migrate for Magento 2.

In the example below we will be migrating the Magento 1 Files from the Magestore_Productfile to Akeneo.

Upload all the files from the media/productfile Magento directory to the Akeneo server in the app/custom-import folder.

Now the files are ready and you can create the CSV file with the following query for the Magento 1 Database:

In the example query below there are 10 file attributes which are created in Akeneo with codes like `file1`, `file2` etc. Besides that these attributes are localisable and the files will be imported for only the locale nl_NL.

SELECT 
 p.sku,
 CASE WHEN count(*) > 0 THEN REPLACE(SUBSTRING_INDEX(GROUP_CONCAT(f.filename ORDER BY f.filename ASC SEPARATOR ','), ',', 1), ' ', '_') ELSE '' END AS 'file1-nl_NL',
 CASE WHEN count(*) > 1 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.filename ORDER BY f.filename ASC SEPARATOR ','), ',', 2), ',', -1), ' ', '_') ELSE '' END AS 'file2-nl_NL',
 CASE WHEN count(*) > 2 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.filename ORDER BY f.filename ASC SEPARATOR ','), ',', 3), ',', -1), ' ', '_') ELSE '' END AS 'file3-nl_NL',
 CASE WHEN count(*) > 3 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.filename ORDER BY f.filename ASC SEPARATOR ','), ',', 4), ',', -1), ' ', '_') ELSE '' END AS 'file4-nl_NL',
 CASE WHEN count(*) > 4 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.filename ORDER BY f.filename ASC SEPARATOR ','), ',', 5), ',', -1), ' ', '_') ELSE '' END AS 'file5-nl_NL',
 CASE WHEN count(*) > 5 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.filename ORDER BY f.filename ASC SEPARATOR ','), ',', 6), ',', -1), ' ', '_') ELSE '' END AS 'file6-nl_NL',
 CASE WHEN count(*) > 6 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.filename ORDER BY f.filename ASC SEPARATOR ','), ',', 7), ',', -1), ' ', '_') ELSE '' END AS 'file7-nl_NL',
 CASE WHEN count(*) > 7 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.filename ORDER BY f.filename ASC SEPARATOR ','), ',', 8), ',', -1), ' ', '_') ELSE '' END AS 'file8-nl_NL',
 CASE WHEN count(*) > 8 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.filename ORDER BY f.filename ASC SEPARATOR ','), ',', 9), ',', -1), ' ', '_') ELSE '' END AS 'file9-nl_NL',
 CASE WHEN count(*) > 9 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.filename ORDER BY f.filename ASC SEPARATOR ','), ',', 10), ',', -1), ' ', '_') ELSE '' END AS 'file10-nl_NL'
 FROM productfile_product as pf INNER JOIN catalog_product_entity AS p ON pf.product_id = p.entity_id INNER JOIN productfile AS f ON pf.productfile_id = f.productfile_id 
 GROUP BY p.sku 

The above query can also be added so you can import files from for example the Amasty ProductAttachment Module.

Besides the files you can also migrate the File Titles with the following query

SELECT 
 p.sku,
 CASE WHEN count(*) > 0 THEN REPLACE(SUBSTRING_INDEX(GROUP_CONCAT(f.title ORDER BY f.title ASC SEPARATOR ','), ',', 1), ' ', '_') ELSE '' END AS 'titlefile1-nl_NL',
 CASE WHEN count(*) > 1 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.title ORDER BY f.title ASC SEPARATOR ','), ',', 2), ',', -1), ' ', '_') ELSE '' END AS 'titlefile2-nl_NL',
 CASE WHEN count(*) > 2 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.title ORDER BY f.title ASC SEPARATOR ','), ',', 3), ',', -1), ' ', '_') ELSE '' END AS 'titlefile3-nl_NL',
 CASE WHEN count(*) > 3 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.title ORDER BY f.title ASC SEPARATOR ','), ',', 4), ',', -1), ' ', '_') ELSE '' END AS 'titlefile4-nl_NL',
 CASE WHEN count(*) > 4 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.title ORDER BY f.title ASC SEPARATOR ','), ',', 5), ',', -1), ' ', '_') ELSE '' END AS 'titlefile5-nl_NL',
 CASE WHEN count(*) > 5 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.title ORDER BY f.title ASC SEPARATOR ','), ',', 6), ',', -1), ' ', '_') ELSE '' END AS 'titlefile6-nl_NL',
 CASE WHEN count(*) > 6 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.title ORDER BY f.title ASC SEPARATOR ','), ',', 7), ',', -1), ' ', '_') ELSE '' END AS 'titlefile7-nl_NL',
 CASE WHEN count(*) > 7 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.title ORDER BY f.title ASC SEPARATOR ','), ',', 8), ',', -1), ' ', '_') ELSE '' END AS 'titlefile8-nl_NL',
 CASE WHEN count(*) > 8 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.title ORDER BY f.title ASC SEPARATOR ','), ',', 9), ',', -1), ' ', '_') ELSE '' END AS 'titlefile9-nl_NL',
 CASE WHEN count(*) > 9 THEN REPLACE(SUBSTRING_INDEX(SUBSTRING_INDEX(GROUP_CONCAT(f.title ORDER BY f.title ASC SEPARATOR ','), ',', 10), ',', -1), ' ', '_') ELSE '' END AS 'titlefile10-nl_NL'
 FROM productfile_product as pf INNER JOIN catalog_product_entity AS p ON pf.product_id = p.entity_id INNER JOIN productfile AS f ON pf.productfile_id = f.productfile_id 
 GROUP BY p.sku