我使用命令 firebase deploy --only "functions:onWikiWrite"
部署了一个 firebase 函数。
我收到此错误:Error: Functions did not deploy properly.
。 firebase 函数日志说
"status":{"code":7,"message":"没有足够的权限来(重新)配置触发器(存储桶 myBucket 的权限被拒绝)。请为存储桶的编辑者角色授予所有者权限并尝试再次。
打字稿代码?
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
import serviceAccount from "/Users/300041370/Downloads/serviceKey.json";
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
const buckObj = functions.storage.bucket("myBucket").object();
export const onWikiWrite = buckObj.onFinalize(async (object) => {
const filePath = object.name ?? "test.json";
const bucket = admin.storage().bucket("myBucket");
bucket.file(filePath).download().then((data) => {
const contents = data[0];
data = {"key": "value"};
const doc = admin.firestore().collection("myCollection").doc();
doc.set(data);
});
});