首页 > 解决方案 > 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 存储有相同的限制”

标签: javascriptfirebasegoogle-cloud-storagefirebase-storage

解决方案


我之前回答的解决方案是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"
});

推荐阅读