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

Function main

asset/snippets/exportAssets.js:22–62  ·  view source on GitHub ↗
(dumpFilePath, contentType)

Source from the content-addressed store, hash-verified

20// usage: node exportAssets.js <gs://my-bucket/my-assets.txt> <content_type>
21
22async function main(dumpFilePath, contentType) {
23 // [START asset_quickstart_export_assets]
24 /**
25 * TODO(developer): Uncomment these variables before running the sample.
26 */
27 // const dumpFilePath = 'gs://my-bucket/my-assets.txt';
28 // const contentType = 'RESOURCE';
29
30 const {AssetServiceClient} = require('@google-cloud/asset');
31 const client = new AssetServiceClient();
32
33 async function exportAssets() {
34 const projectId = await client.getProjectId();
35 const projectResource = `projects/${projectId}`;
36
37 // TODO(developer): choose the dump file path
38 // const dumpFilePath = 'Dump file path, e.g.: gs://<my_bucket>/<my_asset_file>'
39 const request = {
40 parent: projectResource,
41 contentType: contentType,
42 outputConfig: {
43 gcsDestination: {
44 uri: dumpFilePath,
45 },
46 },
47 };
48
49 // Handle the operation using the promise pattern.
50 const [operation] = await client.exportAssets(request);
51
52 // Operation#promise starts polling for the completion of the operation.
53 const [result] = await operation.promise();
54
55 // Do things with with the response.
56 console.log(result);
57 }
58 exportAssets().catch(err => {
59 throw err;
60 });
61 // [END asset_quickstart_export_assets]
62}
63
64main(...process.argv.slice(2)).catch(err => {
65 console.error(err.message);

Callers 1

exportAssets.jsFile · 0.70

Calls 1

exportAssetsFunction · 0.85

Tested by

no test coverage detected