问题描述
app.get("/signedurl/:filename",async (req,res,next) => {
const { filename } = req.params;
// These options will allow temporary uploading of the file with outgoing
// Content-Type: application/octet-stream header.
const options = {
version: "v4",action: "write",expires: Date.Now() + 15 * 60 * 1000,// 15 minutes
contentType: "application/octet-stream",} as GetSignedURLconfig;
// Get a v4 signed URL for uploading file
const [url] = await admin
.storage()
.bucket()
.file(filename)
.getSignedUrl(options);
res.json({ url });
});
服务器在firebase功能上运行。
由于在本地环境上进行测试时需要凭据文件,因此我将其部署并访问“ / signedurl / test”以生成测试文件的签名URL。
首先,日志显示错误:Identity and Access Management (IAM) API has not been used in project 794261759992 before or it is disabled.
,因此我启用了API。
然后日志显示错误:Error: Permission iam.serviceAccounts.signBlob is required to perform this operation on service account projects/[$my_project_id]/serviceAccounts/[$my_project_id]@appspot.gserviceaccount.com.
我知道如何添加权限,但是该服务帐户使我感到困惑。
我在Firebase控制台上看到,firebase的服务帐户就像“ firebase-adminsdk-xxxx @ [$ my_project_id] .iam.gserviceaccount.com”。
我认为错误中的服务帐户是针对App引擎的。 但是我什至没有使用App Engine。
那为什么要使用该服务帐户来进行签名?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)