If you're trying to do this, you came to the right place!
Watch this code work in real time: https://twitter.com/CodingDoug/status/945035556555186176
These instructions assume that you already have a Firebase project, and billing is enabled. Billing is required to use the Vision API.
-
Create a project workspace with the Fireabse CLI with Hosting and Functions enabled (with TypeScript).
-
Allow global read and write access to Realtime Database and Storage. (But don't do this in production!!)
-
Copy
index.html
anddrop.js
to yourpublic
web content folder. -
Copy index.ts to the
functions/src
folder. -
npm install firebase-functions firebase-admin @google-cloud/vision
-
Deploy Hosting and Functions with
firebase deploy
-
Navigate to the site URL you're given.
-
Drop a file containing an image (PNG, JPG, GIF, etc)
-
Watch magic happen.
-
User drags an image to the browser.
-
A drop event triggers an upload of that file to Cloud Storage.
-
When the upload is compete, the client pushes a record into Realtime Database with the image download URL.
-
A Cloud Function also triggers when the upload is complete.
- It calls the Google Cloud Vision API with a reference to the file in storage.
- It writes the results of the API (descriptive labels) to the database.
- The UI in the browser is automatically updated with the results of the API.
- https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API
- https://firebase.google.com/docs/storage/web/upload-files
- https://firebase.google.com/docs/functions/gcp-storage-events
- https://firebase.google.com/docs/database/web/read-and-write
- https://cloud.google.com/nodejs/docs/reference/vision/latest/