子目录上 Cloud Storage 的 Cloud Pub/Sub 通知 [英] Cloud Pub/Sub Notifications for Cloud Storage on sub directory

查看:36
本文介绍了子目录上 Cloud Storage 的 Cloud Pub/Sub 通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在子存储桶中监听 GCS 的变化

I want to listen to changes on GCS in sub bucket

我试过了

gsutil notification create -t  my-topic -f json gs://my-bucket

但它会通知我所有对象的变化

but it gives me notification for changes in all objects

有没有办法只从子目录中获取,像这样:

is there a way to get only from sub directory, something like this:

gsutil notification create -t  my-topic -f json gs://my-bucket/sub-dir

推荐答案

确实有一种方法可以将通知限制到存储桶内的目录".请记住,Cloud Storage 是一个平面"存储系统,其中不存在目录的概念;相反,GCS 将名称以 / 结尾的 blob 解释为文件夹,但实际情况是,当在文件夹"内创建对象时,唯一的区别是文件夹名称为对象名称中的前缀.然后,像这样的结构:

There is indeed a way to limit the notifications to a "directory" inside a bucket. Bear in mind that Cloud Storage is a "flat" storage system, where the concept of directory does not exist; instead, GCS interprets blobs that have a name ending in / as a folder, but the reality is that when an object is created inside a "folder", the only difference is that it has the folder name as a prefix in the object name. Then, a structure like:

gs://my-bucket
|_objectA
|_folder
  |_objectB
  |_subfolder
    |_objectC

在对象名称方面将转换为以下内容:

Would translate into the following in terms of object names:

# Object names
gs://my-bucket/objectA
gs://my-bucket/folder/
gs://my-bucket/folder/objectB
gs://my-bucket/folder/subfolder/
gs://my-bucket/folder/subfolder/objectC

知道了,您可以使用-p 选项gsutil notification create 命令一起为要从中获取通知的对象指定前缀路径过滤器.它会是这样的:

Knowing that, you can use the -p option with the gsutil notification create command in order to specify a prefix path filter for the objects that you want to get notifications from. It would be something like:

gsutil notification create -t my-topic -f json -p folder/ gs://my-bucket

请注意,-p 标志只是设置对象的路径前缀,因此您还可以使用它为名称以给定字符串开头的所有对象创建通知警报.在这种情况下,如果这个 给定字符串/ 结尾,您将表明您需要通知您存储桶中文件夹中的对象.

Note that the -p flag just sets the path prefix for an object, so you can use it also to create a notification alert for all objects whose name starts by a given string. In this case, if this given string ends with a /, you will be indicating that you want notifications for objects in a folder in your bucket.

这篇关于子目录上 Cloud Storage 的 Cloud Pub/Sub 通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆