子目录上的Cloud Storage的Cloud Pub/Sub通知 [英] Cloud Pub/Sub Notifications for Cloud Storage on sub directory
问题描述
我想听子存储桶中GCS的更改
I want to listen to changes on GCS in sub bucket
我尝试过
gsutil notification create -t my-topic -f json gs://my-bucket
但它会通知我所有对象
有没有一种方法只能从子目录中获取信息,像这样:
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屋!