Tho*_*hoe 6 node.js google-cloud-storage firebase firebase-storage
我的 Firebase 存储getSignedUrl()下载链接可以使用几天,然后停止工作。错误信息是
SignatureDoesNotMatch
The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.
Run Code Online (Sandbox Code Playgroud)
去年夏天,在 GitHub 上对此进行了长时间的讨论,但我没有看到解决方案。
我正在考虑getDownloadURL()从前端使用而不是getSignedUrl()从后端使用。是getDownloadURL()不太安全的,然后getSignedUrl()?
这是我的代码,主要是从文档中复制的:
SignatureDoesNotMatch
The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.
Run Code Online (Sandbox Code Playgroud)
小智 8
预签名 URL 将在您在字段中提供的日期到期expires。
但是,您在此处看到的问题是管理 SDK 的 KMS 密钥每 7 天轮换一次。因此,如果您使用自动配置的 storage() 库创建 presignedURL,一旦密钥轮换,您的预签名 URL 将不再有效(因为用于签名的密钥不再有效)。因此,您的 URL 的有效期将小于或等于 7 天,具体取决于密钥的期限。
相反,您不需要使用 admin SDK,而是使用Google Cloud Storage npm 模块并使用服务帐户 json 对其进行初始化。
const storage = new Storage({keyFilename: "key.json"});
或者
`const storage = new Storage({credential: require("key.json")});
Google Cloud Storage 签名 URL 的最长持续时间为 7 天。但它也可以更短。再也不会了。我猜 Firebase 存储有相同的限制。
| 归档时间: |
|
| 查看次数: |
6862 次 |
| 最近记录: |