![](/img/trans.png)
[英]Upload File to Google Cloud Storage Bucket Sub Directory using Python
[英]Get Object Notification for Google Cloud Storage Using pub/sub
每當有新對象上傳到存儲桶時,我都想通知腳本。 我創建了一個存儲桶,創建了一個主題,並配置了訂閱。 (點擊此鏈接 )
但是,我的腳本正在等待並且沒有收到任何通知。
這是我的代碼:
poll_notifications('bold-proton-236611', 'projects/bold-proton-236611/subscriptions/processphotos')
def poll_notifications(project, subscription_name):
"""Polls a Cloud Pub/Sub subscription for new GCS events for display."""
# [BEGIN poll_notifications]
subscriber = pubsub_v1.SubscriberClient()
subscription_path = subscriber.subscription_path(project, subscription_name)
def callback(message):
print('Received message:\n{}'.format(summarize(message)))
message.ack()
subscriber.subscribe(subscription_path, callback=callback)
# The subscriber is non-blocking, so we must keep the main thread from
# exiting to allow it to process messages in the background.
print('Listening for messages on {}'.format(subscription_path))
while True:
time.sleep(60)
# [END poll_notifications]
現在可以通過Cloud Functions來實現此目的的更簡單方法。...不確定這是否是您想要的。
在“創建功能”用戶界面上,可以選擇“雲存儲”作為觸發器。
這就是您要完成的工作嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.