javascript - 尝试上传到使用多个元数据生成的 GCP 签名网址时收到 403

标签 javascript node.js google-cloud-platform google-cloud-storage

我生成了一个 GCP 签名网址, header 中包含两个元数据值。

例如, ‘x-goog-meta-reviewer’:‘简’, ‘x-goog-meta-author’:’jack’

当我尝试使用 header 中设置的元数据将文件上传到生成的签名 URL 时。我收到 403 禁止请求。

但有趣的是,如果我只设置一个元数据,相同的代码可以正常工作 ‘x-goog-meta-reviewer’:‘简’ 在两个标题中。

尝试将文件上传到 Google 云时能否不发送两个元数据值?

最佳答案

当您构造 Canonical requests 时你应该记住 规范 header 如下:

1.Make all header names lowercase.

2.Sort all headers by header name using a lexicographical sort by code point value.

3.Separate each header with a newline (/n).

4.Eliminate duplicate header names by creating one header name with a comma-separated list of values. Be sure there is no whitespace between the values, and be sure that the order of the comma-separated list matches the order that the headers appear in your request. For more information, see RFC 7230 section 3.2.

5.Replace any folding whitespace or newlines (CRLF or LF) with a single space. For more information about folding whitespace, see RFC 7230, section 3.2.4..

6.Remove any whitespace around the colon that appears after the header name.

7.For example, using the custom header x-goog-acl: private without removing the space after the colon returns a 403 Forbidden error, because the request signature you calculate does not match the signature Google calculates.

因此,当您计算的请求签名与 Google 计算的签名不匹配时,您可能会收到 403 Forbidden 错误。

关于javascript - 尝试上传到使用多个元数据生成的 GCP 签名网址时收到 403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59879804/

相关文章:

javascript - 使用javascript检测上下滚动

node.js - 指定草稿订单货币 Shopify

node.js - AJAX > MongoDB 查询只工作了五次,然后服务器停止处理请求,我无法刷新页面

google-cloud-platform - 如何检查最新的 Cloud Run 修订版是否已准备好提供服务

javascript - puppeteer 师 : how check if browser is still open and working

javascript - Angular .js : UI not updating when variable changes

javascript - JS : Handle with find() property undefined

node.js - Node js、NVD3.js无法读取未定义的属性baseval

google-bigquery - 从云计算实例访问时 BigQuery 中的 SCOPES_WARNING

google-app-engine - 无法删除 Google Cloud Tasks Queue 上的 appEngineRoutingOverride