Hi. I have created a workflow, part of which grabs an image URL and looks to convert this to base64 so that it can be stored in a DB. The workflow element (updatePartImagesToBase64) that does the conversion works fine when I run it on its own, but when I run the whole workflow, I am getting an error of TypeError: fetch is not a function
[Fri Jan 20 2023 10:17:49 GMT+0000] Evaluating JS query: updatePartImagesToBase64
[Fri Jan 20 2023 10:17:49 GMT+0000] Error evaluating updatePartImagesToBase64: TypeError: fetch is not a function
[Fri Jan 20 2023 10:17:49 GMT+0000] --- Failed running query: updatePartImagesToBase64 ---
[Fri Jan 20 2023 10:17:49 GMT+0000] --- Hit failure, skipping queries: insertParts ---
The 'updatePartImagesToBase64' code is as follow, and loops through an array from the prior Workflow module (makeParts) using the .map function
const newPart = makeParts.data
const getBase64FromUrl = async (url) => {
const data = await fetch(url);
const blob = await data.blob();
return new Promise((resolve) => {
const reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = () => {
const base64data = reader.result;
resolve(base64data);
}
});
}
const base64Image = await Promise.all(makeParts.data.map(async (part, i) => {
newPart[i].thumb = await getBase64FromUrl(part.thumb)
newPart[i].thumb_120x120 = await getBase64FromUrl(part.thumb_120x120)
}));
return newPart
I am no JavaScript expert, so I assume that there may be an issue with the code - but I am not sure why it would work when running on its own and then fail when the whole workflow is run.
Can anyone help me out please...?