Node.js 将google云存储文件转换为base64字符串

Node.js 将google云存储文件转换为base64字符串,node.js,google-cloud-platform,base64,google-cloud-storage,sendgrid,Node.js,Google Cloud Platform,Base64,Google Cloud Storage,Sendgrid,我正在从谷歌云存储检索pdf文件。我需要将此文件转换为base64字符串,以便我可以作为请求传递给api const { Storage } = require("@google-cloud/storage"); const storage = new Storage(options); const bucket = storage.bucket(bucketName); let remoteFile = bucket.file(fileName); 需要将此remo

我正在从谷歌云存储检索pdf文件。我需要将此文件转换为base64字符串,以便我可以作为请求传递给api

const { Storage } = require("@google-cloud/storage");
const storage = new Storage(options);
const bucket = storage.bucket(bucketName);   
let remoteFile = bucket.file(fileName);
需要将此remoteFile对象转换为base64字符串。
实际上,我需要将此远程文件作为附件传递给sendgrid mail api。

正如您在中找到的,您需要首先下载文件内容,然后您可以使用base64对其进行编码

....

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