• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (PHP SDK)
  4. Bucket-Related APIs
  5. PUT Bucket notification

PUT Bucket notification

API Description

You can use this API to set event notification for a bucket. You will be notified of all specified operations performed on the bucket.

Method Definition

1. ObsClient->setBucketNotification(array $parameter)
2. ObsClient->setBucketNotificationAsync(array $parameter, callable $callback)

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

string

Mandatory

Bucket name

TopicConfigurations

indexed array

Optional

Event notification setting list of the bucket

  

ID

string

Optional

Event notification setting ID

Topic

string

Mandatory

URN of the event notification topic. After detecting a specific event in the bucket, OBS sends a message to the topic.

Event

indexed array of strings

Mandatory

Type of events that need to be notified Possible values are:

  • s3:ObjectCreated:*
  • s3:ObjectCreated:Put
  • s3:ObjectCreated:Post
  • s3:ObjectCreated:Copy
  • s3:ObjectCreated:CompleteMultipartUpload
  • s3:ObjectRemoved:*
  • s3:ObjectRemoved:Delete
  • s3:ObjectRemoved:DeleteMarkerCreated

Filter

indexed array

Optional

List of filtering rules

  

Name

string

Optional

Prefix or suffix of object names for filtering. Possible values are:

  • prefix
  • suffix

Value

string

Optional

Keyword of object names for filtering objects by prefix or suffix

Returned Result

Field

Type

Description

HttpStatusCode

integer

HTTP status code

Reason

string

Reason description

RequestId

string

Request ID returned by the OBS server

Sample Code

try{
       $resp = $obsClient -> setBucketNotification([
              'Bucket' => 'bucketname',
              'TopicConfigurations' => [
                    [
                         'ID' => '001',
                         'Topic' => 'urn:smn:region:xxxx:topic1',
                         'Event' => ['s3:ObjectCreated:*'],
                         'Filter' => [
                               ['Name' => 'prefix', 'Value' => 'smn'],
                               ['Name' => 'suffix', 'Value' => '.jpg']
                         ]
                    ]
              ]
       ]);
       printf("RequestId:%s\n", $resp['RequestId']);
}catch (Obs\Common\ObsException $obsException){
       printf("ExceptionCode:%s\n", $obsException->getExceptionCode());
       printf("ExceptionMessage:%s\n", $obsException->getExceptionMessage());
}