I'm trying to upload a Product image using the PrestaShop Web-service.
It is always returning the same error:
<?xml version="1.0" encoding="UTF-8"?>
<prestashop xmlns:xlink="http://www.w3.org/1999/xlink">
<errors>
<error>
<code><![CDATA[66]]></code>
<message><![CDATA[Unable to save this image]]></message>
</error>
</errors>
</prestashop>
My current code looks like this:
const url = this.options.url
+ '/api/images/products/'
+ piezaSchema.querySelector('product>id').childNodes[0].nodeValue
+ '?ws_key='
+ this.options.api;
const file = require('fs').readFileSync(require('path')
.resolve(this.options.ruta
+ '/images/'
+ image.getAttribute('fichero')));
const resp = await fetch(url, {
method: 'POST',
body: 'image=' + file,
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
});
I've tried with different encoding options, sending as 'Content-Type': 'image/jpeg'
, etc.
Thank you all for your time.