如何从Google Cloud Functions NodeJS连接到Google Cloud Storage

Miguel编码器

我有以下代码示例,该示例接收一个bufferedImage及其mimeType,然后将其上传到Google Cloud Storage。

一切正常,但是由于某种原因,我的Google Cloud Function从Storage API收到403错误。

我必须做什么才能使我的GC功能可以访问GC存储?

我在文档中找不到任何可以向我展示如何执行此操作的内容。

const { Storage } = require('@google-cloud/storage');

// Creates a client
const storage = new Storage();

// Lists all buckets in the current project
const buckets = storage.getBuckets();

exports.uploadImage = (bucketName, fileName, imageBuffer, mimeType) => {
  return new Promise((resolve, reject) => {

    let bucket = storage.bucket(bucketName);

    let file = bucket.file(fileName);
    file.save(imageBuffer,
        {
            metadata: { contentType: `image/${mimeType}` },
        },
        ((error) => {
            error ? reject(error) : resolve()
        })
    );
  })
}

这是我得到的错误

{“代码”:403,“错误”:[{“域”:“全局”,“原因”:“禁止”,“消息”:“ [email protected]没有存储空间。 objects.create对blog / e33f9c9d-65f0-4a7f-8332-29846f770e6d的访问权限。“}”,“消息”:“ [email protected]没有storage.objects.create对blog / e33f9c9d的访问权限-65f0-4a7f-8332-29846f770e6d。“}

丹·科尼莱斯库(Dan Cornilescu)

云功能(CF)由特定的服务帐户(在您的情况下[email protected])执行。运行时服务帐户

在函数执行期间,Cloud Functions将服务帐户[email protected]用作身份。

由于您在访问存储区/文件时遇到403错误,这意味着它们不能公开访问,因此您需要为上述服务帐户提供必要的访问权限(至少storage.objects.create在错误消息中已提及)根据您为存储选择并配置访问控制选项

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Hadoop无法连接到Google Cloud Storage

如何从Cloud Functions连接Google Cloud SQL?

如何使用带有 Python 的 Google Cloud Functions 将列表写入 Google Cloud Storage 中的文件

使用私有IP从Google Functions连接到Cloud SQL

Google Cloud Storage与Google Cloud CDN

Google Cloud Functions - 重试

使用Python脚本中的Google Cloud Functions从Google Cloud Storage中读取CSV

从Cloud Function(Python)写入Google Cloud Storage

使用Cloud Functions将文件从Google Cloud Storage传输到Windows VM实例

Google Cloud Functions-Cloud Storage存储桶触发器延迟触发

无法使用Google Cloud Storage和Cloud Functions for Firebase下载文件

使用Cloud Functions for Firebase和@ google-cloud / storage删除图像时出现问题

如何提供Google Cloud Storage映像?

如何从python函数登录Google Cloud Storage?

如何获取Google Cloud Storage的授权令牌

如何从Google Cloud Storage解密文件?

将Google Cloud CDN与Google Cloud Functions连接

安装@ google-cloud / storage后如何解决Firebase Functions中的Typescript类型错误

如何使WebSockets连接到Google Cloud Function?

如何从Google DataFlow连接到Cloud SQL

Google Cloud Storage ACL混淆

Google Cloud Storage Force下载

PHP 的 Google Cloud Storage 问题

Google Cloud Storage - 权限不足

如何通过Cloud Functions将文件上传到Cloud Storage并使用Firestore控制对Cloud Storage的访问?

如何从 Google Cloud Functions 中删除文件

Google Cloud Functions 数据存储连接问题

HTTP POST Google Cloud Functions NodeJS

如何从Cloud Run连接到Google Cloud Datastore?