首页 > 解决方案 > Google Cloud Storage Signed URL PUT Content-MD5

问题描述

I'm trying to create GCS signed URLs: https://cloud.google.com/storage/docs/access-control/create-signed-urls-program#signing-language

I want to have my clients upload directly to GCS. However, I'm running into the classic SignatureDoesNotMatch error. I think it might be something to do with the Content-MD5 digest.

I have a question about the documentation. In 2b, it says you can add an MD5 digest. In the example below that, it looks like the digest might be base64 encoded or something, but the instructions say nothing about encoding the digest. Anyone have any experience with this?

edit: in my latest run, I stopped using MD5 digests, and everything worked fine.

标签: uploadgoogle-cloud-storagepre-signed-url

解决方案


你猜对了,MD5 摘要必须是base64 编码的。

当您使用 MD5 摘要创建签名 URL 时,您的PUT请求必须包含标头(如此Content-MD5指定)。

引用标准:

Content-MD5   = "Content-MD5" ":" md5-digest
md5-digest    = <base64 of 128 bit MD5 digest as per RFC 1864>

MD5 摘要是根据实体主体的内容计算的,包括已应用的任何内容编码,但不包括应用于消息主体的任何传输编码。

进入签名的 MD5 摘要是md5-digest上面的(因此是 base64)。

此外,这仅适用于PUT对象上传(不适用于POST或可恢复上传)。如上所述,在使用内容编码 ( Content-Encoding: gzip) 时应小心。


推荐阅读