【问题标题】:Cloud Storage download URLs fail after three days, maybe due to Content-Type?三天后 Cloud Storage 下载 URL 失败,可能是由于 Content-Type?
【发布时间】:2019-08-09 10:19:15
【问题描述】:

三天后,我的 Cloud Storage 签名下载 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 日,所以这不是问题。

Google 关于Signed URLs 的文档说语法是Content_Typecontent-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 不会接受该代码。键中不允许使用连字符。

Google 关于签名 URL 的文档说

As needed. If you provide a content-type, the client (browser) must provide this HTTP header set to the same value.

As neededOptional 不同。

我的 .mp3 文件和我的 .webm 下载 URL 都失败了,因此文件的内容是什么并不重要。

【问题讨论】:

标签: firebase google-cloud-platform google-cloud-storage


【解决方案1】:

三天后,我的下载 URL 仍然有效。好像

file.getSignedUrl({
    action: 'read',
    expires: '03-17-2025',
    content_type: 'audio/mp3'
})

就是答案。

【讨论】:

  • 问题又回来了。今天是 3 月 27 日,3 月 24 日及之前的所有下载 URL 均无效。
猜你喜欢
  • 2018-08-02
  • 2014-03-14
  • 2014-10-17
  • 2016-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-03
  • 1970-01-01
相关资源
最近更新 更多