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

Function main

storagetransfer/quickstart.js:16–72  ·  view source on GitHub ↗
(projectId = 'my-project', gcsSourceBucket, gcsSinkBucket)

Source from the content-addressed store, hash-verified

14'use strict';
15
16async function main(projectId = 'my-project', gcsSourceBucket, gcsSinkBucket) {
17 // [START storagetransfer_quickstart]
18
19 // Imports the Google Cloud client library
20 const {
21 StorageTransferServiceClient,
22 } = require('@google-cloud/storage-transfer');
23
24 /**
25 * TODO(developer): Uncomment the following lines before running the sample.
26 */
27 // Your project id
28 // const projectId = 'my-project'
29
30 // The ID of the GCS bucket to transfer data from
31 // const gcsSourceBucket = 'my-source-bucket'
32
33 // The ID of the GCS bucket to transfer data to
34 // const gcsSinkBucket = 'my-sink-bucket'
35
36 // Creates a client
37 const client = new StorageTransferServiceClient();
38
39 /**
40 * Creates a one-time transfer job.
41 */
42 async function quickstart() {
43 // Creates a request to transfer from the source bucket to
44 // the sink bucket
45 const createRequest = {
46 transferJob: {
47 projectId: projectId,
48 transferSpec: {
49 gcsDataSource: {bucketName: gcsSourceBucket},
50 gcsDataSink: {bucketName: gcsSinkBucket},
51 },
52 status: 'ENABLED',
53 },
54 };
55
56 // Runs the request and creates the job
57 const [transferJob] = await client.createTransferJob(createRequest);
58
59 const runRequest = {
60 jobName: transferJob.name,
61 projectId: projectId,
62 };
63 await client.runTransferJob(runRequest);
64
65 console.log(
66 `Created and ran a transfer job from ${gcsSourceBucket} to ${gcsSinkBucket} with name ${transferJob.name}`
67 );
68 }
69
70 quickstart();
71 // [END storagetransfer_quickstart]
72}
73

Callers 1

quickstart.jsFile · 0.70

Calls 1

quickstartFunction · 0.70

Tested by

no test coverage detected