1

I have gotten started with the help of this thread, giving me a gsutil command:

gsutil notification create \
-t bucketcfpubsub -f json \
-e OBJECT_FINALIZE gs://bucketcfpubsub

With which I got this message published:

b'{\n "kind": "storage#object",\n "id": "bucketcfpubsub/test.txt/1544681756538155",\n "selfLink": "https://www.googleapis.com/storage/v1/b/bucketcfpubsub/o/test.txt",\n "name": "test.txt",\n "bucket": "bucketcfpubsub",\n "generation": "1544681756538155",\n "metageneration": "1",\n "contentType": "text/plain",\n "timeCreated": "2018-12-13T06:15:56.537Z",\n "updated": "2018-12-13T06:15:56.537Z",\n "storageClass": "STANDARD",\n "timeStorageClassUpdated": "2018-12-13T06:15:56.537Z",\n "size": "1938",\n "md5Hash": "sDSXIvkR/PBg4mHyIUIvww==",\n "mediaLink": "https://www.googleapis.com/download/storage/v1/b/bucketcfpubsub/o/test.txt?generation=1544681756538155&alt=media",\n "crc32c": "UDhyzw==",\n "etag": "CKvqjvuTnN8CEAE="\n}\n'

You can see it more 'readably' here

However, this documentation guide hints that we could trim that down to specific metadata that we're interested in. For example, the name of the file, with "objectId". But it doesn't exactly say how this can be implemented through gsutil. In the above wall of text, there is also "timeCreated" and "size".

I would like to set up a notification that outputs the name of the file uploaded as the MESSAGE, and timeCreated and size as attributes.

Could anyone please explain how the input code can be manipulated to achieve this?

Larry Cai
  • 881
  • 1
  • 11
  • 24

1 Answers1

1

There's no way to change the payload to only include a subset of fields. The notification payloads always include the full object metadata if you specify JSON_API_V1 for the payloadFormat.

The only alternative is to set payloadFormat to NONE. This will send no payload at all, but you can still extra some info from the attributes of the notification. For your use case, the attributes contain objectId, but not size and timeCreated. For those additional fields, you'll need to read the full payload.

To specify no payload with gsutil, use the -f none option. See for details: https://cloud.google.com/storage/docs/gsutil/commands/notification#options

jterrace
  • 64,866
  • 22
  • 157
  • 202