| 42 | const storage = new Storage(); |
| 43 | |
| 44 | async function setObjectContexts() { |
| 45 | const file = storage.bucket(bucketName).file(fileName); |
| 46 | |
| 47 | // Create/Update Object Contexts |
| 48 | // Object Contexts live in the 'contexts' field, not the 'metadata' field. |
| 49 | const [metadata] = await file.setMetadata({ |
| 50 | contexts: { |
| 51 | custom: { |
| 52 | 'team-owner': {value: 'storage-team'}, |
| 53 | priority: {value: 'high'}, |
| 54 | }, |
| 55 | }, |
| 56 | }); |
| 57 | |
| 58 | console.log(`Updated Object Contexts for ${fileName}:`); |
| 59 | console.log(JSON.stringify(metadata.contexts, null, 2)); |
| 60 | } |
| 61 | |
| 62 | setObjectContexts().catch(console.error); |
| 63 | // [END storage_set_object_contexts] |