MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

storage/getMetadataNotifications.js:25–66  ·  view source on GitHub ↗

* This application demonstrates how to perform basic operations on files with * the Google Cloud Storage API. * * For more information, see the README.md under /storage and the documentation * at https://cloud.google.com/storage/docs.

(bucketName = 'my-bucket', notificationId = '1')

Source from the content-addressed store, hash-verified

23 */
24
25function main(bucketName = 'my-bucket', notificationId = '1') {
26 // [START storage_print_pubsub_bucket_notification]
27 /**
28 * TODO(developer): Uncomment the following lines before running the sample.
29 */
30 // The ID of your GCS bucket
31 // const bucketName = 'your-unique-bucket-name';
32
33 // The ID of the notification
34 // const notificationId = '1';
35
36 // Imports the Google Cloud client library
37 const {Storage} = require('@google-cloud/storage');
38
39 // Creates a client
40 const storage = new Storage();
41
42 async function getMetadata() {
43 try {
44 // Get the notification metadata
45 const [metadata] = await storage
46 .bucket(bucketName)
47 .notification(notificationId)
48 .getMetadata();
49
50 console.log(`ID: ${metadata.id}`);
51 console.log(`Topic: ${metadata.topic}`);
52 console.log(`Event Types: ${metadata.event_types}`);
53 console.log(`Custom Attributes: ${metadata.custom_attributes}`);
54 console.log(`Payload Format: ${metadata.payload_format}`);
55 console.log(`Object Name Prefix: ${metadata.object_name_prefix}`);
56 console.log(`Etag: ${metadata.etag}`);
57 console.log(`Self Link: ${metadata.selfLink}`);
58 console.log(`Kind: ${metadata.kind}`);
59 } catch (error) {
60 console.error('Error executing get metadata:', error.message || error);
61 }
62 }
63
64 getMetadata();
65 // [END storage_print_pubsub_bucket_notification]
66}
67main(...process.argv.slice(2));

Callers 1

Calls 1

getMetadataFunction · 0.85

Tested by

no test coverage detected