Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 853
Md Umair Avatar asked Jul 07 '26 23:07

Md Umair


1 Answers

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....
});
like image 156
guillaume blaquiere Avatar answered Jul 10 '26 16:07

guillaume blaquiere



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!