(
projectId = 'cloud-devrel-public-resources',
bucketName = `nodejs-storage-samples-${uuid.v4()}`,
srcFileName = 'test.txt',
destFileName = path.join(__dirname, `test_${uuid.v4()}.txt`)
)
| 26 | const path = require('path'); |
| 27 | |
| 28 | function main( |
| 29 | projectId = 'cloud-devrel-public-resources', |
| 30 | bucketName = `nodejs-storage-samples-${uuid.v4()}`, |
| 31 | srcFileName = 'test.txt', |
| 32 | destFileName = path.join(__dirname, `test_${uuid.v4()}.txt`) |
| 33 | ) { |
| 34 | // [START storage_download_file_requester_pays] |
| 35 | |
| 36 | /** |
| 37 | * TODO(developer): Uncomment the following lines before running the sample. |
| 38 | */ |
| 39 | // The project ID to bill |
| 40 | // const projectId = 'my-billable-project-id'; |
| 41 | |
| 42 | // The ID of your GCS bucket |
| 43 | // const bucketName = 'your-unique-bucket-name'; |
| 44 | |
| 45 | // The ID of your GCS file |
| 46 | // const srcFileName = 'your-file-name'; |
| 47 | |
| 48 | // The path to which the file should be downloaded |
| 49 | // const destFileName = '/local/path/to/file.txt'; |
| 50 | |
| 51 | // Imports the Google Cloud client library |
| 52 | const {Storage} = require('@google-cloud/storage'); |
| 53 | |
| 54 | // Creates a client |
| 55 | const storage = new Storage(); |
| 56 | |
| 57 | async function downloadFileUsingRequesterPays() { |
| 58 | try { |
| 59 | const options = { |
| 60 | destination: destFileName, |
| 61 | userProject: projectId, |
| 62 | }; |
| 63 | |
| 64 | // Downloads the file |
| 65 | await storage.bucket(bucketName).file(srcFileName).download(options); |
| 66 | |
| 67 | console.log( |
| 68 | `gs://${bucketName}/${srcFileName} downloaded to ${destFileName} using requester-pays requests` |
| 69 | ); |
| 70 | } catch (error) { |
| 71 | console.error( |
| 72 | 'Error executing download file using requester pays:', |
| 73 | error.message || error |
| 74 | ); |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | downloadFileUsingRequesterPays(); |
| 79 | // [END storage_download_file_requester_pays] |
| 80 | } |
| 81 | main(...process.argv.slice(2)); |
no test coverage detected