【问题标题】:Convert google cloud storage file to base64 string将谷歌云存储文件转换为base64字符串
【发布时间】:2023-03-07 06:19:01
【问题描述】:

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

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

需要将此 remoteFile 对象转换为 base64 字符串。 实际上我需要将此 remoteFile 作为附件传递给 sendgrid 邮件 api。

【问题讨论】:

    标签: node.js google-cloud-platform base64 google-cloud-storage sendgrid


    【解决方案1】:

    正如您在library sample 中找到的那样,您需要先下载文件内容,然后您可以随心所欲地使用base64 对其进行编码

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

    【讨论】:

      猜你喜欢
      • 2018-09-20
      • 1970-01-01
      • 1970-01-01
      • 2019-12-13
      • 1970-01-01
      • 2020-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多