I've created an "Image" (i.e. MediaFile) custom attribute for Products called 'user-manual' that will hold a .pdf file, but when I try to run a Transaction to update this attribute I receive the following error:
Wrapped com.demandware.beehive.core.capi.domain.meta.MetaDataException: Invalid value type provided for attribute 'user-manual'.
I tried running the following code to update the attribute:
var File = require('dw/io/File');
var ProductMgr = require('dw/catalog/ProductMgr');
var Transaction = require('dw/system/Transaction');
var targetDir = 'user-manuals';
var newFileName = 'Example-Product-Manual.pdf';
var targetFile = new File('CATALOGS' + File.SEPARATOR + 'my-master-catalog' + File.SEPARATOR + 'default' + File.SEPARATOR + targetDir + File.SEPARATOR + newFileName);
Transaction.wrap(function () {
var saveProduct = ProductMgr.getProduct('example-productid');
if (saveProduct) {
saveProduct.custom['user-manual'] = targetFile;
}
});
I've also tried setting the attribute to the file path string, as it would appear in business manager:
var targetFilePath = targetDir + File.SEPARATOR + newFileName;
Transaction.wrap(function () {
var saveProduct = ProductMgr.getProduct('example-productid');
if (saveProduct) {
saveProduct.custom['user-manual'] = targetFilePath;
}
});
I've verified that the pdf file I'm using exists in the directory above as well.