Example Description
In this example we create a page where you can upload any image. The uploaded image is sent to Google vision API in order to detect labels that are associated with this image.
How We Built It
Backend
vision.jsw - imports the vision NPM module and exports a getLabels function which:
-
Uses secrets manager API to get credentials to Google.
-
Creates a URL for the uploaded image.
-
Sends this URL to Google vision API and returns the unique labels it detected.
Notes:
-
we are also using lodash NPM module to simplify the code for returning unique labels.
-
The secret key used in this example will not be available under your account. In order to make the example work please go to https://cloud.google.com/vision/docs/auth in order to get your own secret key and place it in the secrets manager.
Page Elements
In our site we added the following page elements:
-
Upload & Submit buttons - let the user upload an image.
-
Image - displays the uploaded image.
-
Repeater - displays the labels detected for the uploaded image.
Code
In $w.onReady we added a onAfterSave event handler function that runs after the image was uploaded. The function does the following:
-
Call the getLabels backend function to get the image’s labels.
-
Create an array called imageLabels that holds these labels alongside a unique id for each label.
-
Populates the repeater with the imageLabels array.
Related Examples
Did this help?
|
Thanks for your feedback!
Hide and Show an Image
Show and hide an image according to the clicked button.
Beginner
SendGrid npm Integration
Use SendGrid’s npm module to send emails from your site
Intermediate
Twilio Integration
Integrate with Twilio to make voice calls and send SMS messages
Advanced