将文件上传到 Google 云存储时设置 headers

Set headers on file upload to Google Cloud Storage

根据 documentation,上传到 GoogleCloudStorage 时应该可以设置 objects headers。

Implementation Details

You should specify cache-control only for objects that are accessible to all anonymous users. To be anonymously accessible, an object's ACL must grant READ or FULL_CONTROL permission to AllUsers. If an object is accessible to all anonymous users and you do not specify a cache-control setting, Cloud Storage applies a cache-control setting of 3600 seconds. When serving via XML, Cloud Storage respects the cache-control of the object as set by its metadata.

但是,在使用 google.appengine.api.images.get_serving_url 取回图像时,通过 Google API 添加 headers 似乎不起作用。

gsutil 控制台更改 Cache-Control headers 会产生影响,但需要几天的时间才能在 object 上看到更改(从 gsutil 控制台,再次使用 API.

取回图像时无效

在 Google 的支持下来回 2 个月后,我们发现文件被发送到 Google Cloud Storage 并带有正确的 headers(可以是通过 gsutil 命令检查)。

但是 get_serving_url 函数不遵守 Blob 的 headers(已由 Google 的工程师确认)。

截至 2017 年 8 月 17 日,未来没有解决此问题的计划。 认为有人可能会遇到类似的问题,因为文档中没有相关内容。