Skip to content

Instantly share code, notes, and snippets.

@crysxd
Last active May 11, 2019 11:52
Show Gist options
  • Save crysxd/93bf6ad0d8eb62630ed6c5dbc080cf03 to your computer and use it in GitHub Desktop.
Save crysxd/93bf6ad0d8eb62630ed6c5dbc080cf03 to your computer and use it in GitHub Desktop.
Google's sample node.js code to import a product set into Google Cloud Vision Product Search
importProductSets('your-project-id', 'your-location', 'gs://link/to/csv')
async function importProductSets(projectId, location, gcsUri) {
// Imports the Google Cloud client library
const vision = require('@google-cloud/vision');
// Creates a client
const client = new vision.ProductSearchClient();
/**
* TODO(developer): Uncomment the following line before running the sample.
*/
// const projectId = 'Your Google Cloud project Id';
// const location = 'A compute region name';
// const gcsUri = 'Google Cloud Storage path of the input image'';
// A resource that represents Google Cloud Platform location.
const projectLocation = client.locationPath(projectId, location);
// Set the input configuration along with Google Cloud Storage URI
const inputConfig = {
gcsSource: {
csvFileUri: gcsUri,
},
};
// Import the product sets from the input URI.
const [response, operation] = await client.importProductSets({
parent: projectLocation,
inputConfig: inputConfig,
});
console.log('Processing operation name: ', operation.name);
// synchronous check of operation status
const [result] = await response.promise();
console.log('Processing done.');
console.log('Results of the processing:');
for (const i in result.statuses) {
console.log('Status of processing ', i, 'of the csv:', result.statuses[i]);
// Check the status of reference image
if (result.statuses[i].code === 0) {
console.log(result.referenceImages[i]);
} else {
console.log('No reference image.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment