javascript - Firebase 存储签名不匹配
问题描述
我已经阅读了很多类似的错误,但是,我发现的解决方案对我不起作用。更改个人资料图片时遇到问题,将图片加载到 Google Chrome 时出现以下错误。错误如下:The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method
。
我在服务器中使用的代码如下:
const admin = require('firebase-admin');
admin.initializeApp();
const config = {
action: 'read',
expires: '03-01-2030'
};
thumbFile.getSignedUrl(config)
这是我通过服务器端获取signedUrl() 的代码。为什么我的网址在一周左右后失效?
我已经阅读了以下答案,老实说我担心:“Google Cloud Storage 签名 URL 的最长持续时间是 7 天。但它也可以更短。永远不会更长。我猜 Firebase 存储有相同的限制”
解决方案
我之前回答的解决方案是admin.initializeApp();
必须使用应用程序的serviceAccount
. 该服务帐户是使用从项目中的 Firebase 设置中获取的服务帐户 .json 文件构建的,如下所示:
const serviceAccount = require("./serviceAccountKey.json");
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
storageBucket: "<YOUR APP ID>.appspot.com",
databaseURL: "https://<YOUR APP ID>.firebaseio.com"
});
推荐阅读
- sql - SQL 对不同列的多个查询
- sql-server - SSIS 数据分析任务编辑器返回错误代码
- python - 为什么 Pycharm 在重构时会自动重命名 Jupyter notebook 中的某些方法,而其他方法则不会?
- docker - 使用 k6 docker 映像安装扩展的最佳方式?
- aws-lambda - EventBridge 消息是否总是进入 CloudWatch 日志?
- javascript - 单击按钮后程序两次进入 eventListener
- r - 如何根据字符串的匹配部分合并 R 中的两个数据框?
- java - 如何创建和初始化(在 Java 中)列表
在同一个声明中?(编者请注意:这*不*与列表相同 ) - matlab - 在 MATLAB 中验证 MPC 模型时出错
- python - pandas.read_sql 不返回所有记录