async function fetchImageAndConvertToBase64(imageUrl) {
// Fetch the image
const response = await fetch(imageUrl);
// Check if the fetch was successful
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
// Create a blob object from the response
const blob = await response.blob();
// Convert the blob object to a Base64 encoded string
const base64String = await new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(blob);
});
return base64String;
}