我正在尝试使用file.getSignedUrl()通过Google Cloud Functions(Nodejs)从Firebase Storage获取下载URL.我在Cloud Functions控制台中收到此错误:
{ SigningError: A Forbidden error was returned while attempting to retrieve an access token for the Compute Engine built-in service account. This may be because the Compute Engine instance does not have the correct permission scopes specified. Permission iam.serviceAccounts.signBlob is required to perform this operation on service account projects/myapp-cd94d/serviceAccounts/myapp-cd94d@appspot.gserviceaccount.com.
at SigningError (/user_code/node_modules/@google-cloud/storage/build/src/file.js:58:9)
at authClient.sign.then.catch.err (/user_code/node_modules/@google-cloud/storage/build/src/file.js:1019:22)
at process._tickDomainCallback (internal/process/next_tick.js:135:7) name: 'SigningError' }
Run Code Online (Sandbox Code Playgroud)
我将代码从添加Firebase Admin SDK复制到您的服务器文档中.serviceAccountKey.json我的functions文件夹里有我的.firebase …
我使用 firebase-admin 和 firebase-functions 在 Firebase 存储中上传文件。
我在存储中有这个规则:
service firebase.storage {
match /b/{bucket}/o {
match /images {
allow read;
allow write: if false;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我想使用以下代码获取公共 URL:
const config = functions.config().firebase;
const firebase = admin.initializeApp(config);
const bucketRef = firebase.storage();
server.post('/upload', async (req, res) => {
// UPLOAD FILE
await stream.on('finish', async () => {
const fileUrl = bucketRef
.child(`images/${fileName}`)
.getDownloadUrl()
.getResult();
return res.status(200).send(fileUrl);
});
});
Run Code Online (Sandbox Code Playgroud)
但我有这个错误.child is not a function。如何使用 firebase-admin 获取文件的公共 url?
google-cloud-storage firebase firebase-storage firebase-admin
我正在编写一个firebase云功能,该功能记录最近上传的文件到实时数据库的下载链接:
exports.recordImage = functions.storage.object().onFinalize((object) => {
});
Run Code Online (Sandbox Code Playgroud)
“对象”使我可以访问两个变量“ selfLink”和“ mediaLink”,但是当它们在浏览器中输入时,它们都返回以下内容:
Anonymous caller does not have storage.objects.get access to ... {filename}
Run Code Online (Sandbox Code Playgroud)
因此,它们不是公共链接。如何在此触发功能内获取公共下载链接?
firebase ×3