我正在尝试将服务帐户密钥包含到我的存储功能中,以便能够通过在此处遵循过时示例来获得长期签名的 url
我已经从 IAM 下载了 JSON 格式的密钥。我试图将它保存在我的函数旁边
-functions/storage/resizeProfileImg.js
-functions/storage/service-account-credentials.json
-functions/index.js
-functions/admin.js
其中 resizeProfileImg.js 是我的函数并像这样调用它
const { Storage } = require('@google-cloud/storage');
const storage = new Storage({ projectId: projectId ,keyFilename: './service-account-credentials.json'})
但是在部署后触发该功能时出现错误
错误:ENOENT:没有这样的文件或目录,打开“/srv/service-account-credentials.json”
我什至试图像这样不断地添加它
const serviceAccountCredentials = require('./accountKey/service-account-credentials.json')
const { Storage } = require('@google-cloud/storage');
const storage = new Storage({ projectId: projectId ,keyFilename: serviceAccountCredentials})
但后来我收到一个错误
类型错误:路径必须是字符串。收到 { type: 'service_account',...
知道如何正确执行此操作
在 Cloud Functions 中,当前目录.
不是源文件所在的位置。它是部署函数文件夹的地方。由于您的凭据文件位于名为“storage”的子目录中,因此您需要在路径中使用它。
const serviceAccountCredentials = require('./storage/service-account-credentials.json')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句