3

I have an blob within Google Apps Script. How can I convert it to an base64 encoded string in order to write it to other APIs? FileReader seems not to work ...

2 Answers2

5

You could try this:

Utilities.base64Encode(blob.getBytes());

Ref docs here.

ADW
  • 4,177
  • 1
  • 14
  • 22
0
const convertImageToDataUri = () => {
  const imageUrl = 'https://i.imgur.com/6rl9Atu.png';
  const blob = UrlFetchApp.fetch(imageUrl).getBlob();
  const base64String = Utilities.base64Encode(blob.getBytes());
  return `data:image/png;base64,${base64String}`;
};