Google cloud storage 如何更改Google云存储中存在对象的所有特定文件的元数据?

Google cloud storage 如何更改Google云存储中存在对象的所有特定文件的元数据?,google-cloud-storage,mime-types,content-type,Google Cloud Storage,Mime Types,Content Type,我已经上传了数千个文件到谷歌存储,我发现所有文件都缺少内容类型,所以我的网站无法正确获取 我想知道我是否可以设置一些策略,比如同时更改所有文件的内容类型,例如,我的bucket中有一堆.html文件 a/b/index.html a/c/a.html a/c/a/b.html a/a.html . . . 可以在不同的位置使用一个命令设置所有.html文件的内容类型吗 没有唯一的命令来实现您正在寻找的行为—一个命令来编辑所有对象的元数据—但是,gcloud有一个命令来编辑元数据,您可以在bas

我已经上传了数千个文件到谷歌存储,我发现所有文件都缺少内容类型,所以我的网站无法正确获取

我想知道我是否可以设置一些策略,比如同时更改所有文件的内容类型,例如,我的bucket中有一堆.html文件

a/b/index.html
a/c/a.html
a/c/a/b.html
a/a.html
.
.
.

可以在不同的位置使用一个命令设置所有.html文件的内容类型吗

没有唯一的命令来实现您正在寻找的行为—一个命令来编辑所有对象的元数据—但是,gcloud有一个命令来编辑元数据,您可以在bash脚本上使用该命令来对bucket中的所有对象进行循环

1.-选项1是在bash脚本上使用gcloud命令setmeta:

# kinda pseudo code here.

# get the list with all your object's names and iterate over the metadata edition command.

for OUTPUT in $(get_list_of_objects_names)
do

gsutil setmeta -h "[METADATA_KEY]:[METADATA_VALUE]" gs://[BUCKET_NAME]/[OBJECT_NAME]
# the "gs://[BUCKET_NAME]/[OBJECT_NAME]" would be your object name.

done

2。-也可以创建一个C++脚本来实现同样的事情:

namespace gcs = google::cloud::storage;
using ::google::cloud::StatusOr;
[](gcs::Client client, std::string bucket_name, std::string object_name,
   std::string key, std::string value) {

# you would need to find list all the objects, while on the loop, you can edit the metadata of the object.

for (auto&& object_metadata : client.ListObjects(bucket_name)) {

  string bucket_name=object_metadata->bucket(), object_name=object_metadata->name();

  StatusOr<gcs::ObjectMetadata> object_metadata =
      client.GetObjectMetadata(bucket_name, object_name);

  gcs::ObjectMetadata desired = *object_metadata;
  desired.mutable_metadata().emplace(key, value);

  StatusOr<gcs::ObjectMetadata> updated =
      client.UpdateObject(bucket_name, object_name, desired,
                          gcs::Generation(object_metadata->generation()))
}

}
你可以做:

gsutil -m setmeta -h Content-Type:text/html gs://your-bucket/**.html

是的,我第一次尝试了这个,但它不能覆盖不同路径中的所有文件。你能说更多你所说的“在不同路径中”是什么意思吗?对不起,回复太晚了,我搞错了。你提供的方式很好!!!多谢各位