I'm using Commerce version 12 and looking at the Catalog import using CSV files and XML mapping files,
I'm having trouble getting images to be linked to the prodcuts / variants I import.
I see that the value I set in the file is saved in the DB, but the file itself is not uploaded, and the field value in the CMS editor is empty.
If I try and add an image using the editor, the field value saved in the DB is in a very different format
I read it too fast, and missed the "CSV" part. It's still true then, you can't upload the image files to CMS system in Commerce Manager. You have to upload them to CMS, get their GUIDs then link them to the products. It sounds like it would be easier to write a scheduled job to handle that for you.
Embedding images during the import is quite heavy and time-consuming process, consider that you have a large image set with different image groups for thumbnail, gallery... to upload. A practice is to implement a schedule job to handle that.
You could either place the image on a hard drive or upload it somewhere in the CMS, then in the schedule job you can load the image file from drive or CMS, perform the rezising ..., and upload it into Episerver. Below is some sample code we used to upload an images folder to Epi for CMS version 10 and Commerce version 11
private void UploadImageIntoEpi(string imagesSourcePath, EPiServer.Core.ContentFolder uploadFolder)
var fileEntries = System.IO.Directory.GetFiles(imagesSourcePath);
foreach (var fileEntry in fileEntries)
var existingMedia =
.FirstOrDefault(x => x.Name.Equals(Path.GetFileName(fileEntry)));
if (existingMedia != null)
//Get a suitable MediaData type from extension
var mediaType = _contentMediaResolver.GetFirstMatching(Path.GetExtension(fileEntry));
var contentType = _contentTypeRepository.Load(mediaType);
//Get a new empty file data
var media = _contentRepository.GetDefault<MediaData>(uploadFolder.ContentLink,
media.Name = Path.GetFileName(fileEntry);
//Create a blob in the binary container
var blob = _blobFactory.CreateBlob(media.BinaryDataContainer,
using (var fs = new FileStream(fileEntry, FileMode.Open))
//Assign to file and publish changes
media.BinaryData = blob;
catch (Exception ex)
_logger.Error("Upload image error " + Path.GetFullPath(fileEntry), ex);
Then from the uploaded media, you can then get its contentLink and create a CommerceMedia like this
var commerceMedia = new CommerceMedia(media.ContentLink, "Image", groupName, order);
and finally add the created commerceMedia to the CommerceMediaCollection of the target product.
I hope this will help.