Md Umair
Md Umair

Reputation: 55

Convert google cloud storage file to base64 string

i am retrieving a pdf file from google cloud storage. I need to convert this file to base64 string so that i can pass to api as request.This is is nodejs

const { Storage } = require("@google-cloud/storage");
const storage = new Storage(options);
const bucket = storage.bucket(bucketName);   
let remoteFile = bucket.file(fileName);

Need to convert this remoteFile object to base64 string. Actually i need to pass this remoteFile as attachment to sendgrid mail api.

Upvotes: 3

Views: 2591

Answers (1)

guillaume blaquiere
guillaume blaquiere

Reputation: 75735

As you can find here in the library sample, you need to download the file content first, and then you can do what you want with, encoded it in base64 if you want

....

remoteFile.download().then(function(data) {
  const file = data[0];
  ... convert base64 and continue here....
});

Upvotes: 4

Related Questions