事件通知
更新时间:2026-07-27
put_notification
本接口用于指定bucket上增加通知规则。
注意:
- 只有bucket owner或者full control权限才能获取这个bucket的配置。
- 如果不是bucket owner则返回403,如果对应的文件不存在则返回404。
相关参数的详细解释请参见PutNotification接口。
C++
1void put_notification(Client &client) {
2 NotificationConfiguration configuration;
3 NotificationRule rule;
4 rule.id = "test-notification";
5 rule.name = "cpp-sdk-notification";
6 rule.app_id = "cpp-sdk-example";
7 rule.status = "enabled";
8 rule.resources.push_back(g_bucket + "/");
9 rule.events.push_back("PutObject");
10 NotificationApp app;
11 app.id = "cpp-sdk-example";
12 app.event_url = "https://example.com/bos-notification";
13 rule.apps.push_back(app);
14 configuration.notifications.push_back(rule);
15 PutNotificationRequest request(g_bucket, configuration);
16 PutNotificationResponse response;
17 client.put_notification(request, &response);
18 print_common_response(response);
19}
get_notification
本接口用于获取指定bucket上的通知规则。
相关参数的详细解释请参见GetNotification接口。
C++
1void get_notification(Client &client) {
2 GetNotificationRequest request(g_bucket);
3 GetNotificationResponse response;
4 client.get_notification(request, &response);
5 print_common_response(response);
6 if (response.is_fail()) {
7 return;
8 }
9 const std::vector<NotificationRule> &rules = response.configuration().notifications;
10 std::cout << "notification rule count: " << rules.size() << std::endl;
11 for (size_t i = 0; i < rules.size(); ++i) {
12 std::cout << " rule[" << i << "]: " << rules[i].id
13 << ", status: " << rules[i].status
14 << ", event count: " << rules[i].events.size()
15 << ", app count: " << rules[i].apps.size() << std::endl;
16 }
17}
delete_notification
本接口用于删除指定bucket上的通知规则。
注意:
该接口为一次性全部删除当前bucket下全部规则
相关参数的详细解释请参见DeleteNotification接口。
C++
1void delete_notification(Client &client) {
2 DeleteNotificationRequest request(g_bucket);
3 DeleteNotificationResponse response;
4 client.delete_notification(request, &response);
5 print_common_response(response);
6}
评价此篇文章
