Hi,
I’m working on encoding a picture to as base64 string and I managed to create run code script that works. But when I try to run it for each picture in sequence, it never finished the first iteration - seems like it never comes to a resolve / reject. But I see that the base64 string i set on the object - so the code runs the actions with the variable.
Both me and ChatGPT is out of ideas - any skilled developers here that could take a look?
The code encodes the file content URL of the picture and returns the base64 string to a action variable and runs the actions “updatePicture” this sets the base64 in a string field in the run time object.
return new Promise((resolve, reject) => {
fetch(fileContentURL)
.then(response => response.blob()) // Fetch the image as a Blob
.then(blob => {
const reader = new FileReader();
// Once the reader finishes reading, resolve the promise
reader.onloadend = () => {
const base64 = reader.result; // The base64 string
updatePicture({ base65String: base64 }) // Call the function with base64 string
.then(resolve) // Resolve the promise with the update result
.catch(reject); // Handle errors from the updatePicture function
};
reader.onerror = (error) => {
reject(error); // Reject the promise if FileReader encounters an error
};
reader.readAsDataURL(blob); // Start reading the blob as a data URL
})
.catch(reject); // Reject the promise if fetch or blob fails
});