* This application demonstrates how to perform basic operations on bucket and * file Access Control Lists 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', fileName = 'test.txt', userEmail = 'jdobry@google.com' )
| 23 | */ |
| 24 | |
| 25 | function main( |
| 26 | bucketName = 'my-bucket', |
| 27 | fileName = 'test.txt', |
| 28 | userEmail = 'jdobry@google.com' |
| 29 | ) { |
| 30 | // [START storage_add_file_owner] |
| 31 | /** |
| 32 | * TODO(developer): Uncomment the following lines before running the sample. |
| 33 | */ |
| 34 | // The ID of your GCS bucket |
| 35 | // const bucketName = 'your-unique-bucket-name'; |
| 36 | |
| 37 | // The name of the file to access |
| 38 | // const fileName = 'file.txt'; |
| 39 | |
| 40 | // The email address of the user to add |
| 41 | // const userEmail = 'user-email-to-add'; |
| 42 | |
| 43 | // Imports the Google Cloud client library |
| 44 | const {Storage} = require('@google-cloud/storage'); |
| 45 | |
| 46 | // Creates a client |
| 47 | const storage = new Storage(); |
| 48 | |
| 49 | async function addFileOwner() { |
| 50 | try { |
| 51 | await storage |
| 52 | .bucket(bucketName) |
| 53 | .file(fileName) |
| 54 | .acl.owners.addUser(userEmail); |
| 55 | |
| 56 | console.log(`Added user ${userEmail} as an owner on file ${fileName}.`); |
| 57 | } catch (error) { |
| 58 | console.error( |
| 59 | 'Error executing add file owner ACL:', |
| 60 | error.message || error |
| 61 | ); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | addFileOwner(); |
| 66 | // [END storage_add_file_owner] |
| 67 | } |
| 68 | main(...process.argv.slice(2)); |
no test coverage detected