{"id":107976,"date":"2022-01-20T14:40:15","date_gmt":"2022-01-20T14:40:15","guid":{"rendered":"https:\/\/randomnerdtutorials.com\/?p=107976"},"modified":"2024-03-06T14:11:51","modified_gmt":"2024-03-06T14:11:51","slug":"esp32-cam-display-pictures-firebase-web-app","status":"publish","type":"post","link":"https:\/\/randomnerdtutorials.com\/esp32-cam-display-pictures-firebase-web-app\/","title":{"rendered":"ESP32-CAM: Display Pictures in Firebase Web App"},"content":{"rendered":"\n<p>In this guide, you&#8217;ll create a Firebase Web App to display the last picture taken with an ESP32-CAM saved in the Firebase Storage. The Web App also shows the date and time that the last photo was taken. The web app is freely hosted on Firebase servers, and you can access it from anywhere.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" fetchpriority=\"high\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-CAM-Firebase-Web-App.jpg?resize=1200%2C675&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM Display Pictures in Firebase Web App\" class=\"wp-image-108007\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-CAM-Firebase-Web-App.jpg?w=1280&amp;quality=100&amp;strip=all&amp;ssl=1 1280w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-CAM-Firebase-Web-App.jpg?resize=300%2C169&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-CAM-Firebase-Web-App.jpg?resize=1024%2C576&amp;quality=100&amp;strip=all&amp;ssl=1 1024w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-CAM-Firebase-Web-App.jpg?resize=768%2C432&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure><\/div>\n\n\n<p>This article is Part 2 of this previous tutorial: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-cam-save-picture-firebase-storage\/\">ESP32-CAM Save Picture in Firebase Storage<\/a>. Follow that tutorial first before proceeding. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Project Overview<\/h2>\n\n\n\n<p>In this tutorial (Part 2), you&#8217;ll create a web app to display the last picture taken with the ESP32-CAM and saved on the Firebase Storage (see this <a href=\"https:\/\/randomnerdtutorials.com\/esp32-cam-save-picture-firebase-storage\/\">previous tutorial<\/a>). <\/p>\n\n\n\n<p>The following diagram shows a high-level overview of the project we&#8217;ll build\u2014programming the ESP32-CAM and setting up the Firebase Project with Storage was done in Part 1. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"750\" height=\"616\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-CAM-Firebase-Storage-Web-App-Project-Overview.png?resize=750%2C616&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM Firebase Storage Project Overview\" class=\"wp-image-108009\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-CAM-Firebase-Storage-Web-App-Project-Overview.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-CAM-Firebase-Storage-Web-App-Project-Overview.png?resize=300%2C246&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>Firebase hosts your web app over a global CDN using Firebase Hosting and provides an SSL certificate. You can access your web app from anywhere using the Firebase-generated domain name.<\/li>\n\n\n\n<li>The web application displays the last picture saved on Firebase Storage on the <span class=\"rnthl rntliteral\">data\/photo.jpg<\/span> path.<\/li>\n\n\n\n<li>It also displays info about when the picture was taken (date and time).<\/li>\n\n\n\n<li>If the web page is open, and meanwhile, there&#8217;s a new picture, you need to press the Refresh button, so that it gets the new picture from the storage path.<\/li>\n\n\n\n<li>Later, you can update the web app to do this automatically. For example, you can save the time the last picture was taken to <a href=\"https:\/\/randomnerdtutorials.com\/esp32-firebase-realtime-database\/\">Firebase Realtime Database (RTDB)<\/a>. You can then, detect changes on the database, and refresh the web page as needed to display the last picture (we may cover this in a future more advanced tutorial).<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p>Before you start creating the Firebase Web App, you need to check the following prerequisites.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Creating a Firebase Project<\/h3>\n\n\n\n<p>You should have followed the following tutorial first:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-cam-save-picture-firebase-storage\/\">ESP32-CAM Save Picture in Firebase Storage<\/a><\/li>\n<\/ul>\n\n\n\n<p>The ESP32-CAM must be running the code provided in that tutorial so that there&#8217;s a picture saved on Firebase Storage. The Firebase Storage must be set up also as shown in the tutorial.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Enabling Anonymous User<\/h3>\n\n\n\n<p>To make the web app as simple as possible, we won&#8217;t add an authentication form to the web app. We&#8217;ll use the anonymous user method\u2014any user can see the ESP32-CAM pictures. To do that, you need to enable an Anonymous user in your Firebase project console.<\/p>\n\n\n\n<p>Go to your project in the Firebase console. Then, go to <strong>Authentication <\/strong>&gt; <strong>Sign-In<\/strong> method. Click on <strong>Add new provider<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" decoding=\"async\" width=\"896\" height=\"443\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/Add-provider-firebase-authentication.png?resize=896%2C443&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Project Add Sign In Provider\" class=\"wp-image-110289\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/Add-provider-firebase-authentication.png?w=896&amp;quality=100&amp;strip=all&amp;ssl=1 896w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/Add-provider-firebase-authentication.png?resize=300%2C148&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/Add-provider-firebase-authentication.png?resize=768%2C380&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 896px) 100vw, 896px\" \/><\/figure><\/div>\n\n\n<p>Select the Anonymous sign-in provider.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"939\" height=\"298\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/Firebase-sign-in-provider.png?resize=939%2C298&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Enable anonymous sign-in Firebase\" class=\"wp-image-110290\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/Firebase-sign-in-provider.png?w=939&amp;quality=100&amp;strip=all&amp;ssl=1 939w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/Firebase-sign-in-provider.png?resize=300%2C95&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/04\/Firebase-sign-in-provider.png?resize=768%2C244&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 939px) 100vw, 939px\" \/><\/figure><\/div>\n\n\n<p>Finally, enable the Anonymous sign-in.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"748\" height=\"253\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/enable-anonymous-user-firebase.png?resize=748%2C253&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Enable Anonymous User Firebase\" class=\"wp-image-110291\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/enable-anonymous-user-firebase.png?w=748&amp;quality=100&amp;strip=all&amp;ssl=1 748w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2022\/01\/enable-anonymous-user-firebase.png?resize=300%2C101&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 748px) 100vw, 748px\" \/><\/figure><\/div>\n\n\n<p>If you want to add an authentication form to your web app, you can take inspiration from this project: <a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-firebase-web-app-sensor\/\">ESP32\/ESP8266: Firebase Web App to Display Sensor Readings (with Authentication)<\/a>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Installing Required Software<\/h3>\n\n\n\n<p>Before getting started, you need to install the required software to create the Firebase Web App. Here&#8217;s a list of the software you need to install (click on the links for instructions):<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-firebase-web-app\/#install-vs-code\">Visual Studio Code<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-firebase-web-app\/#install-nodejs\">Node.JS LTS version<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/esp32-firebase-web-app\/#install-firebase-tools\">Install Firebase Tools<\/a><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1) Add an App to Your Firebase Project<\/h2>\n\n\n\n<p><strong>1)<\/strong> Go to your Firebase project Console and add an app to the project you created in the previous tutorial by clicking on the <strong>+Add app <\/strong>button. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"365\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/Firebase-Add-App-to-Project.png?resize=750%2C365&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Add App to Project\" class=\"wp-image-107442\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/Firebase-Add-App-to-Project.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/Firebase-Add-App-to-Project.png?resize=300%2C146&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p><strong>2)<\/strong> Select the web app icon.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"328\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/Firebase-Add-Web-App-to-Project.png?resize=750%2C328&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Add Web App to Project\" class=\"wp-image-107443\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/Firebase-Add-Web-App-to-Project.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/Firebase-Add-Web-App-to-Project.png?resize=300%2C131&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p><strong>3)<\/strong> Give your app a name. Then, check the box next to&nbsp;<strong>\u221a Also set up Firebase Hosting for this App<\/strong>. Click <strong>Register app<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"552\" height=\"601\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/add-firebase-to-web-app-example.png?resize=552%2C601&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Add Web App to Project\" class=\"wp-image-107458\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/add-firebase-to-web-app-example.png?w=552&amp;quality=100&amp;strip=all&amp;ssl=1 552w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/add-firebase-to-web-app-example.png?resize=276%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 276w\" sizes=\"(max-width: 552px) 100vw, 552px\" \/><\/figure><\/div>\n\n\n<p id=\"firebaseconfig-object\"><strong>4)<\/strong>&nbsp;Then, copy the&nbsp;<span class=\"rnthl rntliteral\">firebaseConfig<\/span>&nbsp;object and save it because you&#8217;ll need it later.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"666\" height=\"210\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/app-firebase-config-object.png?resize=666%2C210&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Add Web App to Project\" class=\"wp-image-107462\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/app-firebase-config-object.png?w=666&amp;quality=100&amp;strip=all&amp;ssl=1 666w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/app-firebase-config-object.png?resize=300%2C95&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 666px) 100vw, 666px\" \/><\/figure><\/div>\n\n\n<p>After this, you can also access the&nbsp;<span class=\"rnthl rntliteral\">firebaseConfig<\/span>&nbsp;object if you go to your Project Settings in your Firebase console.<\/p>\n\n\n\n<p><strong>5)<\/strong> Click&nbsp;<strong>Next<\/strong>&nbsp;on the proceeding steps, and finally on <strong>Continue to console<\/strong>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2) Setting Up a Firebase Web App Project (VS Code)<\/h2>\n\n\n\n<p>Follow the next steps to create a Firebase Web App Project using VS Code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"create-project-folder\">1) Creating a Project Folder<\/h3>\n\n\n\n<p id=\"create-project-folder\"><strong>1)<\/strong> Create a folder on your computer to save your Firebase project\u2014for example, <span class=\"rnthl rntliteral\"><em>Firebase-Project<\/em><\/span> on the Desktop.<\/p>\n\n\n\n<p><strong>2)<\/strong> Open VS Code. Go to <strong>File<\/strong> &gt; <strong>Open Folder&#8230;<\/strong> and select the folder you&#8217;ve just created.<\/p>\n\n\n\n<p><strong>3)<\/strong> Go to <strong>Terminal <\/strong>&gt; <strong>New Terminal<\/strong>. A new Terminal window should open on your project path.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"746\" height=\"163\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Terminal-Window-Firebase-Folder-Project.png?resize=746%2C163&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Install Firebase Tools 2\" class=\"wp-image-106193\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Terminal-Window-Firebase-Folder-Project.png?w=746&amp;quality=100&amp;strip=all&amp;ssl=1 746w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Terminal-Window-Firebase-Folder-Project.png?resize=300%2C66&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 746px) 100vw, 746px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"firebase-login\">2) Firebase Login<\/h3>\n\n\n\n<p><strong>4)<\/strong> On the previous Terminal window, type the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>firebase <\/strong>login<\/code><\/pre>\n\n\n\n<p><strong>5)<\/strong> You&#8217;ll be asked to collect CLI usage and error reporting information. Enter &#8220;<strong>n<\/strong>&#8221; and press <strong>Enter<\/strong> to deny.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"397\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Terminal-Window-Login-Firebase-VS-Code.png?resize=750%2C397&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Login Firebase VS Code Terminal Window\" class=\"wp-image-106194\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Terminal-Window-Login-Firebase-VS-Code.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Terminal-Window-Login-Firebase-VS-Code.png?resize=300%2C159&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p><strong>Note:<\/strong> If you are already logged in, it will show a message saying: &#8220;Already logged in as user@gmail.com&#8221;.<\/p>\n\n\n\n<p><strong>6)<\/strong> After this, it will pop up a new window on your browser to login into your firebase account.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"648\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Login-Firebase-Account.png?resize=750%2C648&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Login Firebase Account\" class=\"wp-image-106195\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Login-Firebase-Account.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Login-Firebase-Account.png?resize=300%2C259&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p><strong>7)<\/strong> Allow Firebase CLI to access your google account.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"875\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Login-Firebase-Account-2.png?resize=750%2C875&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Login Firebase Account allow Firebase CLI\" class=\"wp-image-106196\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Login-Firebase-Account-2.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Login-Firebase-Account-2.png?resize=257%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 257w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p><strong>8)<\/strong> After this, Firebase CLI login should be successful. You can close the browser window.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"689\" height=\"454\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Firebase-CLI-Login-Successful.png?resize=689%2C454&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Login Firebase Account allow Firebase CLI Login Successful\" class=\"wp-image-106197\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Firebase-CLI-Login-Successful.png?w=689&amp;quality=100&amp;strip=all&amp;ssl=1 689w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Firebase-CLI-Login-Successful.png?resize=300%2C198&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 689px) 100vw, 689px\" \/><\/figure><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"init-project\">3) Initializing Web App Firebase Project<\/h3>\n\n\n\n<p><strong>9)<\/strong> After successfully login in, run the following command to start a Firebase project directory in the current folder.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>firebase <\/strong>init<\/code><\/pre>\n\n\n\n<p><strong>10)<\/strong> You&#8217;ll be asked if you want to initialize a Firebase project in the current directory. Enter <strong>Y<\/strong> and hit <strong>Enter<\/strong>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"684\" height=\"187\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Firebase-Start-Project-VS-Code.png?resize=684%2C187&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Login Firebase Account allow Firebase CLI firebase init\" class=\"wp-image-106199\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Firebase-Start-Project-VS-Code.png?w=684&amp;quality=100&amp;strip=all&amp;ssl=1 684w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Firebase-Start-Project-VS-Code.png?resize=300%2C82&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 684px) 100vw, 684px\" \/><\/figure><\/div>\n\n\n<p><strong>11)<\/strong> Then, use up and down arrows and the Space key to select the options. Select the following options:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Hosting<\/strong>: Configure files for Firebase Hosting and (optionally) set up GitHub Action deploys<\/li>\n\n\n\n<li><strong>Storage<\/strong>: Configure a security rules file for Cloud Storage<\/li>\n<\/ul>\n\n\n\n<p>The selected options will show up with a green asterisk. Then, hit <strong>Enter<\/strong>. <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"180\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/create-firebase-project-with-storage.png?resize=750%2C180&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Login Firebase Account allow Firebase CLI firebase init\" class=\"wp-image-107977\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/create-firebase-project-with-storage.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/create-firebase-project-with-storage.png?resize=300%2C72&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p><strong>12)<\/strong> Select the option &#8220;Use an existing project&#8221;\u2014it should be highlighted in blue\u2014then hit Enter.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"658\" height=\"228\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Firebase-Project-Setup-VS-Code.png?resize=658%2C228&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Project Setup VS Code\" class=\"wp-image-106201\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Firebase-Project-Setup-VS-Code.png?w=658&amp;quality=100&amp;strip=all&amp;ssl=1 658w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/Firebase-Project-Setup-VS-Code.png?resize=300%2C104&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 658px) 100vw, 658px\" \/><\/figure><\/div>\n\n\n<p><strong>13)<\/strong> After that, select the Firebase project for this directory\u2014it should be <strong>the project created in this previous tutorial<\/strong>. In my case, it is called <span class=\"rnthl rntliteral\">esp-firebase-demo<\/span>. Then hit Enter.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"646\" height=\"216\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/add-firebase-project-VS-Code.png?resize=646%2C216&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Login Firebase Account allow Firebase CLI firebase init\" class=\"wp-image-106880\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/add-firebase-project-VS-Code.png?w=646&amp;quality=100&amp;strip=all&amp;ssl=1 646w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/add-firebase-project-VS-Code.png?resize=300%2C100&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 646px) 100vw, 646px\" \/><\/figure><\/div>\n\n\n<p><strong>14)<\/strong> Then, select the hosting options as shown below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>What do you want to use as your public directory? Hit <strong>Enter <\/strong>to select <strong>public<\/strong>.<\/li>\n\n\n\n<li>Configure as a single-page app (rewrite urls to \/index.html)? <strong>No<\/strong><\/li>\n\n\n\n<li>Set up automatic builds and deploys with GitHub? <strong>No<\/strong><\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"657\" height=\"277\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/firebase-hosting-setup-all-options.png?resize=657%2C277&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase initialization complete\" class=\"wp-image-106240\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/firebase-hosting-setup-all-options.png?w=657&amp;quality=100&amp;strip=all&amp;ssl=1 657w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/firebase-hosting-setup-all-options.png?resize=300%2C126&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 657px) 100vw, 657px\" \/><\/figure><\/div>\n\n\n<p><strong>15)<\/strong> Then, press Enter on the following question to select the default file for storage rules.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>What file should be used for Storage Rules?(<strong>storage.rules<\/strong>). Hit <strong>Enter<\/strong>.<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"683\" height=\"68\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/Firebase-Project-Setup-Firebase-Storage-Rules.png?resize=683%2C68&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Login Firebase Account allow Firebase CLI firebase init\" class=\"wp-image-108012\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/Firebase-Project-Setup-Firebase-Storage-Rules.png?w=683&amp;quality=100&amp;strip=all&amp;ssl=1 683w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/Firebase-Project-Setup-Firebase-Storage-Rules.png?resize=300%2C30&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 683px) 100vw, 683px\" \/><\/figure><\/div>\n\n\n<p><strong>16)<\/strong> The Firebase project should now be initialized successfully. Notice that VS code created some essential files under your project folder.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"382\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/firebase-project-app-created-successfully.png?resize=750%2C382&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Project Files Created successfully\" class=\"wp-image-106297\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/firebase-project-app-created-successfully.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/08\/firebase-project-app-created-successfully.png?resize=300%2C153&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<p>The <span class=\"rnthl rntliteral\">index.html<\/span> file contains some HTML text to build a web page. For now, leave the default HTML text. The idea is to replace that with your own HTML text to create a custom web page for your needs. We&#8217;ll do that later in this tutorial.<\/p>\n\n\n\n<p><strong>17)<\/strong> To check if everything went as expected, run the following command on the VS Code Terminal window.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>firebase <\/strong>deploy<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"659\" height=\"322\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/firebase-first-deploy-test-app.png?resize=659%2C322&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase App First Deploy Testing\" class=\"wp-image-107463\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/firebase-first-deploy-test-app.png?w=659&amp;quality=100&amp;strip=all&amp;ssl=1 659w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/firebase-first-deploy-test-app.png?resize=300%2C147&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 659px) 100vw, 659px\" \/><\/figure><\/div>\n\n\n<p>You should get a <strong>Deploy complete!<\/strong> message and an URL to the Project Console and the Hosting URL.<\/p>\n\n\n\n<p><strong>18)<\/strong> Copy the hosting URL and paste it into a web browser window. You should see the following web page. You can access that web page from anywhere in the world.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"773\" height=\"495\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/firebase-hosting-complete.png?resize=773%2C495&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\" Firebase Account\" class=\"wp-image-106885\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/firebase-hosting-complete.png?w=773&amp;quality=100&amp;strip=all&amp;ssl=1 773w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/firebase-hosting-complete.png?resize=300%2C192&amp;quality=100&amp;strip=all&amp;ssl=1 300w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/09\/firebase-hosting-complete.png?resize=768%2C492&amp;quality=100&amp;strip=all&amp;ssl=1 768w\" sizes=\"(max-width: 773px) 100vw, 773px\" \/><\/figure><\/div>\n\n\n<p>The web page you&#8217;ve seen previously is built with the HTML file placed in the <span class=\"rnthl rntliteral\">public<\/span> folder of your Firebase project. By changing the content of that file, you can create your own web app. That&#8217;s what we&#8217;re going to do in the next section.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity is-style-wide\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3) Creating Firebase Web App<\/h2>\n\n\n\n<p>Now that you&#8217;ve created a Firebase project app successfully on VS Code, follow the next steps to customize the app to display the picture saved on Firebase Storage.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">index.html<\/h3>\n\n\n\n<p>Copy the following to your <span class=\"rnthl rntliteral\">index.html<\/span> file. This HTML file creates a simple web page that displays the last picture saved on the Firebase Storage and the time it was taken (<a href=\"https:\/\/randomnerdtutorials.com\/esp32-cam-save-picture-firebase-storage\/\">created on this previous project<\/a>). <\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-html\">&lt;!DOCTYPE html&gt;\n&lt;html lang=&quot;en&quot;&gt;\n&lt;head&gt;\n    &lt;meta charset=&quot;UTF-8&quot;&gt;\n    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;\n    &lt;title&gt;ESP Firebase App&lt;\/title&gt;\n\n    &lt;link rel=&quot;stylesheet&quot; href=&quot;https:\/\/use.fontawesome.com\/releases\/v5.7.2\/css\/all.css&quot; integrity=&quot;sha384-fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr&quot; crossorigin=&quot;anonymous&quot;&gt;\n    &lt;link rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; href=&quot;style.css&quot;&gt;\n\n    &lt;!-- The core Firebase JS SDK is always required and must be listed first --&gt;\n    &lt;script src=&quot;https:\/\/www.gstatic.com\/firebasejs\/8.10.0\/firebase-app.js&quot;&gt;&lt;\/script&gt;\n\n    &lt;!-- TODO: Add SDKs for Firebase products that you want to use\n        https:\/\/firebase.google.com\/docs\/web\/setup#available-libraries --&gt;\n    &lt;script src=&quot;https:\/\/www.gstatic.com\/firebasejs\/8.8.1\/firebase-auth.js&quot;&gt;&lt;\/script&gt;\n    &lt;script src=&quot;https:\/\/www.gstatic.com\/firebasejs\/8.10.0\/firebase-storage.js&quot;&gt;&lt;\/script&gt;\n\n\n    &lt;script&gt;\n    \/\/ REPLACE WITH YOUR web app's Firebase configuration\n    const firebaseConfig = {\n      apiKey: &quot;&quot;,\n      authDomain: &quot;&quot;,\n      databaseURL: &quot;&quot;,\n      projectId: &quot;&quot;,\n      storageBucket: &quot;&quot;,\n      messagingSenderId: &quot;&quot;,\n      appId: &quot;&quot;\n    };\n    \/\/ Initialize Firebase\n    firebase.initializeApp(firebaseConfig);\n    \n    \/\/ Get a reference to the storage service, which is used to create references in your storage bucket\n    var storage = firebase.storage();\n\n    \/\/ Create a storage reference from our storage service\n    var storageRef = storage.ref();\n\n&lt;\/script&gt;\n&lt;script src=&quot;app.js&quot; defer&gt;&lt;\/script&gt;\n\n&lt;\/head&gt;\n&lt;body&gt;\n  &lt;div class=&quot;topnav&quot;&gt;\n    &lt;h1&gt;ESP32-CAM Web App &lt;i class=&quot;fas fa-camera&quot;&gt;&lt;\/i&gt;&lt;\/h1&gt;\n  &lt;\/div&gt;\n    &lt;p&gt;&lt;img id=&quot;img&quot; width=&quot;500px&quot;&gt;&lt;\/p&gt; \n    &lt;p&gt;Last picture taken: &lt;span id=&quot;date-time&quot;&gt;&lt;\/span&gt;&lt;\/p&gt;\n    &lt;button onclick=&quot;window.location.reload();&quot;&gt;Refresh&lt;\/button&gt;\n  &lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Firebase-ESP\/raw\/main\/ESP32-CAM-Save-Picture-Firebase-Storage\/index.html\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>You need to modify the code with your own <span class=\"rnthl rntliteral\">firebaseConfig<\/span> object\u2014the one you&#8217;ve got <a href=\"#firebaseconfig-object\">in this step<\/a>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">How it Works<\/h4>\n\n\n\n<p>Let&#8217;s take a quick look at the HTML file, or <a href=\"#style-css\">skip to the next section<\/a>.<\/p>\n\n\n\n<p>In the <span class=\"rnthl rntliteral\"><span style=\"color: #333399;\">&lt;head&gt;<\/span><\/span> of the HTML file, we must add all the required metadata.<\/p>\n\n\n\n<p>The web page&#8217;s title is <strong>ESP Firebase App<\/strong>, but you can change it in the following line.<\/p>\n\n\n\n<pre class=\"wp-block-code language-html\"><code>&lt;title&gt;ESP Firebase App&lt;\/title&gt;<\/code><\/pre>\n\n\n\n<p>The following line allows us to use <a href=\"https:\/\/fontawesome.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">fontawesome icons<\/a>:<\/p>\n\n\n\n<pre class=\"wp-block-code language-html\"><code>&lt;link rel=\"stylesheet\" href=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/font-awesome\/6.5.1\/css\/all.min.css\"><\/code><\/pre>\n\n\n\n<p>Reference an external <span class=\"rnthl rntliteral\">style.css<\/span> file to format the HTML page.<\/p>\n\n\n\n<pre class=\"wp-block-code language-html\"><code>&lt;link rel=\"stylesheet\" type=\"text\/css\" href=\"style.css\"&gt;<\/code><\/pre>\n\n\n\n<p>You must add the following line to be able to use Firebase with your app.<\/p>\n\n\n\n<pre class=\"wp-block-code language-html\"><code>&lt;script src=\"https:\/\/www.gstatic.com\/firebasejs\/8.10.0\/firebase-app.js\"&gt;&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p>You must also add any Firebase products you want to use. In this example, we&#8217;re using Storage and Authentication.<\/p>\n\n\n\n<pre class=\"wp-block-code language-html\"><code>&lt;script src=\"https:\/\/www.gstatic.com\/firebasejs\/8.8.1\/firebase-auth.js\"&gt;&lt;\/script&gt;\n&lt;script src=\"https:\/\/www.gstatic.com\/firebasejs\/8.10.0\/firebase-storage.js\"&gt;&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p>Then, replace the <span class=\"rnthl rntliteral\">firebaseConfig<\/span> object with the one you&#8217;ve gotten <a href=\"#firebaseconfig-object\">from this step<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>const firebaseConfig = {\n  apiKey: \"AIzaSyA2sJiXEcOWVZqdrh348eUO3aHothDz7sE\",\n  authDomain: \"esp-firebase-demo.firebaseapp.com\",\n  databaseURL: \"https:\/\/esp-firebase-demo-default-rtdb.europe-west1.firebasedatabase.app\",\n  projectId: \"esp-firebase-demo\",\n  storageBucket: \"esp-firebase-demo.appspot.com\",\n  messagingSenderId: \"1086300631316\",\n  appId: \"1:1086300631316:web:316410846aaeb0bb8c9201\"\n};<\/code><\/pre>\n\n\n\n<p>Finally, Firebase is initialized, and we create two global variables\u2014<span class=\"rnthl rntliteral\">storage<\/span>, and <span class=\"rnthl rntliteral\">storageRef<\/span>, that refer to Firebase Storage and a reference to the storage service.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>\/\/ Initialize Firebase\nfirebase.initializeApp(firebaseConfig);\n    \n\/\/ Get a reference to the storage service, which is used to create references in your storage bucket\nvar storage = firebase.storage();\n\n\/\/ Create a storage reference from our storage service\nvar storageRef = storage.ref();<\/code><\/pre>\n\n\n\n<p>We&#8217;re done with the metadata. Now, let&#8217;s go to the HTML parts that are visible to the user\u2014go between the <span class=\"rnthl rntliteral\"><span style=\"color: #333399;\">&lt;body&gt;<\/span> and <span class=\"rnthl rntliteral\"><span style=\"color: #333399;\">&lt;\/body&gt;<\/span><\/span> tags.<\/span><\/p>\n\n\n\n<p>We create a top &#8220;navigation&#8221; bar with the name of our app and a small icon from fontawesome.<\/p>\n\n\n\n<pre class=\"wp-block-code language-html\"><code>&lt;div class=\"topnav\"&gt;\n  &lt;h1&gt;ESP32-CAM Web App &lt;i class=\"fas fa-camera\"&gt;&lt;\/i&gt;&lt;\/h1&gt;\n&lt;\/div&gt;<\/code><\/pre>\n\n\n\n<p>The following line creates a paragraph with an image tag where we&#8217;ll display the picture later on. The image tag has a specific id (&#8220;<span class=\"rnthl rntliteral\">img<\/span>&#8220;) so that we can refer to that element in the JavaScript file by its id.<\/p>\n\n\n\n<pre class=\"wp-block-code language-html\"><code>&lt;p&gt;&lt;img id=\"img\" width=\"500px\"&gt;&lt;\/p&gt;<\/code><\/pre>\n\n\n\n<p>Next, we create a paragraph to display the date and time that the picture was taken. There is a <span class=\"rnthl rntliteral\"><span style=\"color: #333399;\">&lt;span&gt;<\/span><\/span> tag with the <span class=\"rnthl rntliteral\">date-time<\/span> id where we&#8217;ll display that information later on.<\/p>\n\n\n\n<pre class=\"wp-block-code language-html\"><code>&lt;p&gt;Last picture taken: &lt;span id=\"date-time\"&gt;&lt;\/span&gt;&lt;\/p&gt;<\/code><\/pre>\n\n\n\n<p> Finally, there&#8217;s a button to refresh the web page (to display a new picture, if that&#8217;s the case).<\/p>\n\n\n\n<pre class=\"wp-block-code language-html\"><code>&lt;button onclick=\"window.location.reload();\"&gt;Refresh&lt;\/button&gt;<\/code><\/pre>\n\n\n\n<p>After making the necessary changes (inserting your <span class=\"rnthl rntliteral\">firebaseConfig<\/span> object), you can save the HTML file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"style-css\">style.css<\/h3>\n\n\n\n<p>Inside the <span class=\"rnthl rntliteral\">public<\/span> folder, create a file called <span class=\"rnthl rntliteral\">style.css<\/span>. To create the file, select the <span class=\"rnthl rntliteral\">public<\/span> folder, and then click on the <strong>+file<\/strong> icon at the top of the File Explorer. Call it <span class=\"rnthl rntliteral\">style.css<\/span>.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"578\" height=\"277\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/Firebase-Project-VS-Code-CSS-File.png?resize=578%2C277&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Create CSS File VS Code\" class=\"wp-image-107545\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/Firebase-Project-VS-Code-CSS-File.png?w=578&amp;quality=100&amp;strip=all&amp;ssl=1 578w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/Firebase-Project-VS-Code-CSS-File.png?resize=300%2C144&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 578px) 100vw, 578px\" \/><\/figure><\/div>\n\n\n<p>Then, copy the following to the <span class=\"rnthl rntliteral\">style.css<\/span> file.<\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-CSS\">html {\r\n    font-family: Arial, Helvetica, sans-serif; \r\n    display: inline-block; \r\n    text-align: center;\r\n  }\r\n  h1 {\r\n    font-size: 1.8rem; \r\n    color: white;\r\n  }\r\n  p { \r\n    font-size: 1.2rem;\r\n  }\r\n  .topnav { \r\n    overflow: hidden; \r\n    background-color: #0A1128;\r\n  }\r\n  body {  \r\n    margin: 0;\r\n  }\r\n  button{\r\n    background-color: #034078;\r\n    border: none;\r\n    padding: 14px 20px;\r\n    text-align: center;\r\n    font-size: 20px;\r\n    border-radius: 4px;\r\n    transition-duration: 0.4s;\r\n    width: 150px;\r\n    color: white;\r\n    cursor: pointer;\r\n  }<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Firebase-ESP\/raw\/main\/ESP32-CAM-Save-Picture-Firebase-Storage\/style.css\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>The CSS file includes some simple styles to make our webpage look better. We won&#8217;t discuss how CSS works in this tutorial.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">JavaScript File<\/h3>\n\n\n\n<p>Create a new file inside the <span class=\"rnthl rntliteral\">public<\/span> folder called <span class=\"rnthl rntliteral\">app.js<\/span>.<\/p>\n\n\n\n<p>The following image show how your web app project folder structure should look like.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"466\" height=\"267\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/Firebase-Web-App-Project-Files.png?resize=466%2C267&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Project VS Code Folder File Structure\" class=\"wp-image-107985\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/Firebase-Web-App-Project-Files.png?w=466&amp;quality=100&amp;strip=all&amp;ssl=1 466w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/Firebase-Web-App-Project-Files.png?resize=300%2C172&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 466px) 100vw, 466px\" \/><\/figure><\/div>\n\n\n<h4 class=\"wp-block-heading\">app.js<\/h4>\n\n\n\n<p>Copy the following to the <span class=\"rnthl rntliteral\">app.js<\/span> file you created previously. <\/p>\n\n\n<pre style=\"max-height: 40em; margin-bottom: 20px;\"><code class=\"language-javascript\">\/\/ Reference to Picture Storage Path\r\nvar imgRef = storageRef.child('data\/photo.jpg');\r\n\r\nfirebase.auth().signInAnonymously().then(function() {\r\n\r\n  imgRef.getDownloadURL().then(function(url){\r\n    \/\/ `url` is the download URL for 'data\/photo.jpg'\r\n    document.querySelector('img').src = url;\r\n    \r\n  }).catch(function(error) {\r\n    console.error(error);\r\n  });\r\n});\r\n\r\nimgRef.getMetadata()\r\n  .then((metadata) =&gt; {\r\n    console.log(metadata);\r\n    date = new Date(metadata.timeCreated);\r\n    console.log(date.getFullYear()+'-' + (date.getMonth()+1) + '-'+date.getDate());\r\n    console.log(date.getHours() + &quot;:&quot; + date.getMinutes() + &quot;:&quot; + date.getSeconds());\r\n    var time = (date.getHours() + &quot;:&quot; + date.getMinutes() + &quot;:&quot; + date.getSeconds());\r\n    var writtenDate = (date.getFullYear()+'-' + (date.getMonth()+1) + '-'+date.getDate());\r\n    document.getElementById(&quot;date-time&quot;).innerHTML = time + &quot; at &quot; + writtenDate;\r\n  })\r\n  .catch((error)=&gt; {\r\n    console.error(error);\r\n  });<\/code><\/pre>\n\t<p style=\"text-align:center\"><a class=\"rntwhite\" href=\"https:\/\/github.com\/RuiSantosdotme\/Firebase-ESP\/raw\/main\/ESP32-CAM-Save-Picture-Firebase-Storage\/app.js\" target=\"_blank\">View raw code<\/a><\/p>\n\n\n\n<p>This file gets the picture saved on the Firebase Storage and the time it was taken and displays that on the HTML page.<\/p>\n\n\n\n<p>First, create a reference to a location on Firebase Storage where the picture is located. In our case,  it is <span class=\"rnthl rntliteral\">data\/photo.jpg<\/span>.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>var imgRef = storageRef.child('data\/photo.jpg');<\/code><\/pre>\n\n\n\n<p>To access Firebase storage, you must be signed in. For simplicity, we sign in as an anonymous user, but you can add login with email and password <a href=\"https:\/\/randomnerdtutorials.com\/esp32-esp8266-firebase-web-app-sensor\/\">like in this tutorial<\/a>. <\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>firebase.auth().signInAnonymously().then(function() {<\/code><\/pre>\n\n\n\n<p>After successfully signing in, you can get the download URL for a file by calling the <span class=\"rnthl rntliteral\">getDownloadURL()<\/span> method on a Cloud Storage reference (<span class=\"rnthl rntliteral\">imgRef<\/span>).<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>imgRef.getDownloadURL().then(function(url){<\/code><\/pre>\n\n\n\n<p>The <span class=\"rnthl rntliteral\">url<\/span> is the download URL for <span class=\"rnthl rntliteral\">&#8216;data\/photo.jpg&#8217;<\/span>. So, now, we can display the picture on the web page by selecting the <span class=\"rnthl rntliteral\">img<\/span> element.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>document.querySelector('img').src = url;<\/code><\/pre>\n\n\n\n<p>Display any errors if something goes wrong in the process.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>}).catch(function(error) {\n  console.error(error);\n});<\/code><\/pre>\n\n\n\n<p>You can find the date and time the picture was taken in its metadata. You can get the picture metadata by using the <span class=\"rnthl rntliteral\">getMetadata()<\/span> method on a storage reference:<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>imgRef.getMetadata()<\/code><\/pre>\n\n\n\n<p>We display all available metadata on the JavaScript console.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>.then((metadata) =&gt; {\n  console.log(metadata);<\/code><\/pre>\n\n\n\n<p>Then, we can get the date and time the picture was taken with <span class=\"rnthl rntliteral\">metadata.timeCreated<\/span>. So, we create a new JavaScript <span class=\"rnthl rntliteral\">date<\/span> object with the date and time saved on the metadata.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>date = new Date(metadata.timeCreated);<\/code><\/pre>\n\n\n\n<p>To learn more about the JavaScript date object, <a href=\"https:\/\/www.w3schools.com\/jsref\/jsref_obj_date.asp\" target=\"_blank\" rel=\"noreferrer noopener\">check this<\/a>.<\/p>\n\n\n\n<p>Then, we create a variable called <span class=\"rnthl rntliteral\">time<\/span> that contains the time in the HH:MM:SS format:<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>var time = (date.getHours() + \":\" + date.getMinutes() + \":\" + date.getSeconds());<\/code><\/pre>\n\n\n\n<p>We create a variable called <span class=\"rnthl rntliteral\">writtenDate<\/span> with the YYYY\/MM\/DD format.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>var writtenDate = (date.getFullYear()+'-' + (date.getMonth()+1) + '-'+date.getDate());<\/code><\/pre>\n\n\n\n<p>Finally, display the date and time on the HTML element with the <span class=\"rnthl rntliteral\">date-time<\/span> id.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>document.getElementById(\"date-time\").innerHTML = time + \" at \" + writtenDate;<\/code><\/pre>\n\n\n\n<p>Catch any errors if something goes wrong in the process of getting the metadata.<\/p>\n\n\n\n<pre class=\"wp-block-code language-javascript\"><code>.catch((error)=&gt; {\n  console.error(error);\n});<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Deploy your App<\/h3>\n\n\n\n<p>After saving the HTML and JavaScript files, deploy your app on VS Code by running the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>firebase<\/strong> deploy<\/code><\/pre>\n\n\n\n<p>Firebase offers a free hosting service to serve your assets and web apps. Then, you can access your web app from anywhere.<\/p>\n\n\n\n<p>The Terminal should display something as follows:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"724\" height=\"312\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/ESP32-ESP8266-Deploy-Firebase-App-VS-Code-1.png?resize=724%2C312&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32 ESP8266 Deploy Firebase Web App\" class=\"wp-image-107548\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/ESP32-ESP8266-Deploy-Firebase-App-VS-Code-1.png?w=724&amp;quality=100&amp;strip=all&amp;ssl=1 724w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/ESP32-ESP8266-Deploy-Firebase-App-VS-Code-1.png?resize=300%2C129&amp;quality=100&amp;strip=all&amp;ssl=1 300w\" sizes=\"(max-width: 724px) 100vw, 724px\" \/><\/figure><\/div>\n\n\n<p>You can use the Hosting URL provided to access your web app from anywhere.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Demonstration<\/h2>\n\n\n\n<p>Congratulations! You successfully deployed your app. It is now hosted on a global CDN using Firebase hosting. You can access your web app from anywhere on the Hosting URL provided. In my case, it is <span class=\"rnthl rntliteral\">https:\/\/esp-firebase-demo.web.app<\/span>.<\/p>\n\n\n\n<p>The web app is responsive, and you can access it using your smartphone, computer, or tablet.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"350\" height=\"715\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-CAM-Web-App-Smartphone-Picture.png?resize=350%2C715&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"ESP32-CAM Firebase Web App Display Picture Smartphone\" class=\"wp-image-108014\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-CAM-Web-App-Smartphone-Picture.png?w=350&amp;quality=100&amp;strip=all&amp;ssl=1 350w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-CAM-Web-App-Smartphone-Picture.png?resize=147%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 147w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/figure><\/div>\n\n\n<p>Reset your ESP32-CAM board, and it should take a new picture when it first starts. Then, click on the web app Refresh button so that it retrieves the latest picture taken.<\/p>\n\n\n\n<p>Go to your project&#8217;s Firebase console&nbsp;<strong>Hosting<\/strong>&nbsp;tab. You can see your app domains, deploy history, and you can even roll back to previous versions of your app.<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"750\" height=\"804\" src=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/ESP32-ESP8266-Firebase-Web-App-Deploy-History.png?resize=750%2C804&#038;quality=100&#038;strip=all&#038;ssl=1\" alt=\"Firebase Web App Deploy History and Domains\" class=\"wp-image-107552\" srcset=\"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/ESP32-ESP8266-Firebase-Web-App-Deploy-History.png?w=750&amp;quality=100&amp;strip=all&amp;ssl=1 750w, https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/10\/ESP32-ESP8266-Firebase-Web-App-Deploy-History.png?resize=280%2C300&amp;quality=100&amp;strip=all&amp;ssl=1 280w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">Wrapping Up<\/h2>\n\n\n\n<p>In this tutorial, you learned how to create a Firebase Web App that interacts with Firebase Storage to display the last image taken with the ESP32-CAM.<\/p>\n\n\n\n<p>You can apply what you learned here to display any other type of files (not just jpeg), and you can change the files in the <span class=\"rnthl rntliteral\">public<\/span> folder to add different functionalities and features to your project. For example, add authentication, display multiple pictures, etc.<\/p>\n\n\n\n<p>If you want to learn more about Firebase, we recommend taking a look at our new eBook:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><a href=\"https:\/\/randomnerdtutorials.com\/firebase-esp32-esp8266-ebook\/\">Firebase Web App with ESP32 and ESP8266<\/a><\/strong><\/li>\n<\/ul>\n\n\n\n<p>We have other resources related to ESP32 and ESP8266 that you may like:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/randomnerdtutorials.com\/learn-esp32-with-arduino-ide\/\">Learn ESP32 with Arduino IDE<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/home-automation-using-esp8266\/\">Home Automation using ESP8266<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/randomnerdtutorials.com\/build-web-servers-esp32-esp8266-ebook\/\">Build Web Servers with ESP32 and ESP8266<\/a><\/li>\n<\/ul>\n\n\n\n<p>Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, you&#8217;ll create a Firebase Web App to display the last picture taken with an ESP32-CAM saved in the Firebase Storage. The Web App also shows the date &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"ESP32-CAM: Display Pictures in Firebase Web App\" class=\"read-more button\" href=\"https:\/\/randomnerdtutorials.com\/esp32-cam-display-pictures-firebase-web-app\/#more-107976\" aria-label=\"Read more about ESP32-CAM: Display Pictures in Firebase Web App\">CONTINUE READING \u00bb<\/a><\/p>\n","protected":false},"author":5,"featured_media":108007,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[281,319,264],"tags":[],"class_list":["post-107976","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-esp32-project","category-esp32-cam","category-project"],"aioseo_notices":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/randomnerdtutorials.com\/wp-content\/uploads\/2021\/11\/ESP32-CAM-Firebase-Web-App.jpg?fit=1280%2C720&quality=100&strip=all&ssl=1","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/107976","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/comments?post=107976"}],"version-history":[{"count":20,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/107976\/revisions"}],"predecessor-version":[{"id":149838,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/posts\/107976\/revisions\/149838"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media\/108007"}],"wp:attachment":[{"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/media?parent=107976"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/categories?post=107976"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/randomnerdtutorials.com\/wp-json\/wp\/v2\/tags?post=107976"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}