我的云存储签名下载URL三天后失效。我想我已经解决了这个问题,所以这个问题可能是其他人的解决方案。三天后再问我这个解决方案是否有效!
下面是完整的错误消息:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>
The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.
</Message>
<StringToSign>
GET 1742169600 /languagetwo-cd94d.appspot.com/Audio%2FSpanish%2FLatin_America-Sofia-Female-IBM%2Fagua.mp3
</StringToSign>
</Error>我在谷歌上搜索了错误消息,看到了一些关于Content-Type问题的讨论。当我将文件上传到存储时,我没有在代码中指定Content-Type。如果我在上传时在代码中设置了contentType,下载URL会立即失败,并显示相同的错误消息。这表明我在正确的轨道上。
file.getSignedUrl({
action: 'read',
expires: '03-17-2025',
contentType: 'audio/mp3'
})下载URL中的过期日期是2025年3月17日,所以这不是问题所在。
谷歌关于Signed URLs的文档称其语法为Content_Type。关于content-type的IETF文档说语法是Content-Type。我试过了
file.getSignedUrl({
action: 'read',
expires: '03-17-2025',
content_type: 'audio/mp3'
})我的文件就可以下载和播放了。我不想再等三天看看它们是否还能继续工作,所以如果还有其他需要修复的地方,请让我知道!
只是为了笑我试过了
file.getSignedUrl({
action: 'read',
expires: '03-17-2025',
content-type: 'audio/mp3'
})而且firebase deploy不会接受代码。键中不允许使用连字符。
谷歌关于已签名URL的文档称
As needed. If you provide a content-type, the client (browser) must provide this HTTP header set to the same value.As needed与Optional不同。
我的.mp3文件和.webm下载URL都失败了,所以文件的内容是什么都无关紧要。
发布于 2019-03-22 21:20:30
三天后,我的下载URL仍然有效。看起来像是
file.getSignedUrl({
action: 'read',
expires: '03-17-2025',
content_type: 'audio/mp3'
})这就是答案。
https://stackoverflow.com/questions/55231676
复制相似问题