scriptPilot
scriptPilot

Reputation: 95

How to convert Google Apps script blob to a base64 encoded string?

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 ...

Upvotes: 3

Views: 2845

Answers (2)

Sonu Kumar
Sonu Kumar

Reputation: 1

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}`;
};

Upvotes: 0

ADW
ADW

Reputation: 4247

You could try this:

Utilities.base64Encode(blob.getBytes());

Ref docs here.

Upvotes: 5

Related Questions