| 42 | const storage = new Storage(); |
| 43 | |
| 44 | async function getObjectContexts() { |
| 45 | // Gets the metadata for the file |
| 46 | const [metadata] = await storage |
| 47 | .bucket(bucketName) |
| 48 | .file(fileName) |
| 49 | .getMetadata(); |
| 50 | |
| 51 | // Contexts are stored in metadata.contexts.custom |
| 52 | if (metadata.contexts && metadata.contexts.custom) { |
| 53 | console.log(`Object Contexts for ${fileName}:`); |
| 54 | |
| 55 | // Iterate through the custom contexts to show values and timestamps |
| 56 | for (const [key, details] of Object.entries(metadata.contexts.custom)) { |
| 57 | console.log(`- Key: ${key}`); |
| 58 | console.log(` Value: ${details.value}`); |
| 59 | console.log(` Created: ${details.createTime}`); |
| 60 | console.log(` Updated: ${details.updateTime}`); |
| 61 | } |
| 62 | } else { |
| 63 | console.log(`No Object Contexts found for ${fileName}.`); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | getObjectContexts().catch(console.error); |
| 68 | // [END storage_get_object_contexts] |