<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vignesh Ravichandran</title>
    <description>The latest articles on DEV Community by Vignesh Ravichandran (@viggy28).</description>
    <link>https://dev.to/viggy28</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F628551%2F2953bd91-9200-4960-8f08-25563d9a7f47.png</url>
      <title>DEV Community: Vignesh Ravichandran</title>
      <link>https://dev.to/viggy28</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/viggy28"/>
    <language>en</language>
    <item>
      <title>Setting up ghost on Raspberry Pi for free</title>
      <dc:creator>Vignesh Ravichandran</dc:creator>
      <pubDate>Mon, 10 May 2021 00:33:00 +0000</pubDate>
      <link>https://dev.to/viggy28/setting-up-ghost-on-raspberry-pi-for-free-11kb</link>
      <guid>https://dev.to/viggy28/setting-up-ghost-on-raspberry-pi-for-free-11kb</guid>
      <description>&lt;p&gt;This is part of my &lt;a href="https://github.com/viggy28/til"&gt;Today I Learnt&lt;/a&gt; series where I share whatever I am learning something new. After having issues with &lt;a href="https://viggy28.dev/article/pain-of-setting-up-port-forwarding-in-xfinity/"&gt;port forwarding in Xfinity&lt;/a&gt; I decided to look for alternative solutions. I have used Cloudflare tunnel (used to be called Argo Tunnel) in the past to expose websites running on my laptop to the Internet. So, I decided to try it out for Ghost blogging site which I am setting up for my dad.&lt;/p&gt;

&lt;p&gt;Things that I had already set up&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://cloudflare.com/"&gt;Cloudflare&lt;/a&gt; free tier account and added the domain&lt;/li&gt;
&lt;li&gt;Raspberry pi with Docker installed&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The overall architecture looks like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pBk3zaCx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/urioejj449ywmzkaoe5o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pBk3zaCx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/urioejj449ywmzkaoe5o.png" alt="overall architecture"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here are the steps which I did:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a docker volume
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker volume create ghost-synergywin-net
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;Create a docker container using &lt;a href="https://hub.docker.com/_/ghost"&gt;ghost&lt;/a&gt; image [1]
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker run -d -e url=http://localhost:3001 -p 3001:2368 --name some-ghost -v ghost-synergywin-net:/var/lib/ghost/content ghost
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;I mapped raspberry pi port 3001 to containers port 2368 and passing environment variable &lt;code&gt;url&lt;/code&gt; as localhost. Mounted the location &lt;code&gt;/var/lib/ghost/content&lt;/code&gt; to &lt;code&gt;ghost-synergywin-net&lt;/code&gt; volume.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Confirm that the ghost site is up
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl http://localhost:3001
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Next I replaced &lt;code&gt;url&lt;/code&gt; environment variable with the actual domain&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;docker run &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="nv"&gt;url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://synergywin.net &lt;span class="nt"&gt;-p&lt;/span&gt; 3001:2368 &lt;span class="nt"&gt;--name&lt;/span&gt; some-ghost &lt;span class="nt"&gt;-v&lt;/span&gt; ghost-synergywin-net:/var/lib/ghost/content ghost
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next is exposing this website securely to the Internet. Because, raspberry pi is running on my Local Area Network (LAN). I need to make it accessible from the Internet. To do that I used &lt;a href="https://www.cloudflare.com/products/argo-tunnel/"&gt;Cloudflare tunnel&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I added the domain &lt;a href="//synergywin.net"&gt;synergywin.net&lt;/a&gt; to Cloudflare&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation"&gt;Installed&lt;/a&gt; [2] cloudflared executable on the Raspberry pi  &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/setup"&gt;Authenticate&lt;/a&gt; [3] cloudflared which creates &lt;code&gt;cert.pem&lt;/code&gt; file&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Created a tunnel&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  cloudflared tunnel create ghost-synergywin-net
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Created a config file for the tunnel
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;credentials-file&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/home/pi/.cloudflared/&amp;lt;uuid&amp;gt;.json&lt;/span&gt;
&lt;span class="na"&gt;tunnel&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;&amp;lt;uuid&amp;gt;&lt;/span&gt;

&lt;span class="na"&gt;ingress&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;hostname&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;synergywin.net&lt;/span&gt;
    &lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;http://localhost:3001&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;service&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;http_status:404&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Added a CNAME in the Cloudflare dashboard for the hostname with .cfargotunnel.com&lt;/li&gt;
&lt;li&gt;Ran tunnel using the above config
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;cloudflared tunnel &lt;span class="nt"&gt;--config&lt;/span&gt; config.yaml run &amp;amp;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Actually, that is it. I am able to reach my dad's blog over the Internet now. &lt;/p&gt;

&lt;p&gt;Bonus, I also got &lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ELPPYjrs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0vz9m3l4otdmjbyw4e5x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ELPPYjrs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0vz9m3l4otdmjbyw4e5x.png" alt="SSL"&gt;&lt;/a&gt;enabled using Cloudflare itself for free with just a click of a radio button :) &lt;/p&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://hub.docker.com/_/ghost"&gt;https://hub.docker.com/_/ghost&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation"&gt;https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/installation&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/setup"&gt;https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/setup&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
    <item>
      <title>Get Started With Firebase Storage</title>
      <dc:creator>Vignesh Ravichandran</dc:creator>
      <pubDate>Mon, 10 May 2021 00:29:45 +0000</pubDate>
      <link>https://dev.to/viggy28/get-started-with-firebase-storage-f7h</link>
      <guid>https://dev.to/viggy28/get-started-with-firebase-storage-f7h</guid>
      <description>&lt;h1&gt;
  
  
  Get Started With Firebase Storage (Web)
&lt;/h1&gt;

&lt;p&gt;Firebase is a developing platform provided by Google to the developers to build dynamic web apps or any mobile apps. Moreover, firebase is providing a lot of features such as Firebase authentication to quickly authenticate the user with the auth state change listener, Real-time database to store the relevant data in JSON like format, Cloud Firestore scalable database keeps your data in-sync across client apps through realtime listeners, and lot more features.&lt;br&gt;
Today, I will be going to talk about a feature that is Firebase Storage and how we can implement it in our web apps. I will specifically discuss the core feature of Firebase Storage. So let's get started.&lt;/p&gt;
&lt;h1&gt;
  
  
  What does Firebase Storage provide to the developers?
&lt;/h1&gt;

&lt;p&gt;Certainly, Firebase Storage is one of the core features to Firebase development platform that lets you upload and share rich content such as images, files, videos into your apps. Cloud Storage lets you securely upload these files directly from mobile devices and web browsers, handling spotty networks with ease. Moreover, the following data is stored in a Google Cloud Storage bucket with a large scale storage solution and high availability.&lt;/p&gt;
&lt;h1&gt;
  
  
  How to implement Firebase Storage in our project?
&lt;/h1&gt;

&lt;p&gt;First, we need to create a firebase project. Follow the steps to create a firebase project so that we could use Firebase Storage functionality to store the image:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to firebase.google.com and sign in&lt;/li&gt;
&lt;li&gt;After sign in, click the 'go-to console' tab.&lt;/li&gt;
&lt;li&gt;Click 'Add project'; then enter your project name, and click continue.&lt;/li&gt;
&lt;li&gt;Disable Google Analytics for this project as of now. However, if you have a google analytics account, then you can enable it for your requirements.&lt;/li&gt;
&lt;li&gt;Finally, click create a project button. Wait for creating the project and click continue.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="/blog-images/firebaseStorage1.png" class="article-body-image-wrapper"&gt;&lt;img src="/blog-images/firebaseStorage1.png" alt="firebase storage 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this tutorial project, I am going to create a directory named 'image-uploader' (you can choose any name). And inside the directory, I will create two files - &lt;strong&gt;index.html and app.js&lt;/strong&gt;. I will be using the &lt;strong&gt;Bootstrap 4 framework&lt;/strong&gt; to build awesome CSS design.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;NOTE - For this tutorial, I am using the VSCode editor to implement the code. You can choose any code editor comfortable with it.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We have to create a connection with the firebase project so that we could upload the images to the Firebase Storage. For that, follow the steps:&lt;/p&gt;

&lt;p&gt;&lt;a href="/blog-images/firebaseStorage2.png" class="article-body-image-wrapper"&gt;&lt;img src="/blog-images/firebaseStorage2.png" alt="firebase storage 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Click the web icon, enter the app name like image-uploader, and click register app.&lt;/li&gt;
&lt;li&gt;Now, you would see the firebase SDK codes. Copy the starting script link and paste it inside the index.html between the head tag.&lt;/li&gt;
&lt;li&gt;And lastly, copy the last script code and paste it inside the app.js file.&lt;/li&gt;
&lt;li&gt;You need to add Bootstrap 4 CSS CDN link, Firebase Storage CDN link, and connect app.js to index.html file.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Bootstrap 4.1.3 CSS CDN link -&lt;/strong&gt; &lt;code&gt;&amp;lt;link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"&amp;gt;&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;Firebase Storage CDN link -&lt;/strong&gt; &lt;code&gt;&amp;lt;script src="https://www.gstatic.com/firebasejs/7.16.1/firebase-storage.js"&amp;gt;&amp;lt;/script&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;We need to set up the storage so that anybody can upload the image without authentication. For this follow the steps:&lt;/p&gt;

&lt;p&gt;&lt;a href="/blog-images/firebaseStorage7.png" class="article-body-image-wrapper"&gt;&lt;img src="/blog-images/firebaseStorage7.png" alt="firebase storage 7"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go the project main screen, click the storage option(left panel).&lt;/li&gt;
&lt;li&gt;Click get started, click next, and choose the Cloud Storage location and click done.&lt;/li&gt;
&lt;li&gt;Go to the Rules tab, replace 'if request.auth != null' with 'if true', and click publish.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="/blog-images/firebaseStorage9.png" class="article-body-image-wrapper"&gt;&lt;img src="/blog-images/firebaseStorage9.png" alt="firebase storage 9"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Index.html
&lt;/h1&gt;

&lt;p&gt;We are going to create a button to select the image from our local machine. And the image directly uploads to the firebase storage.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"utf-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;http-equiv=&lt;/span&gt;&lt;span class="s"&gt;"X-UA-Compatible"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"IE=edge"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://www.gstatic.com/firebasejs/7.16.1/firebase-app.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"https://www.gstatic.com/firebasejs/7.16.1/firebase-storage.js"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;title&amp;gt;&lt;/span&gt;Image-uploader&lt;span class="nt"&gt;&amp;lt;/title&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"description"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"viewport"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"width=device-width, initial-scale=1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"stylesheet"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css"&lt;/span&gt; &lt;span class="na"&gt;integrity=&lt;/span&gt;&lt;span class="s"&gt;"sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"&lt;/span&gt; &lt;span class="na"&gt;crossorigin=&lt;/span&gt;&lt;span class="s"&gt;"anonymous"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"container mt-5"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;h3&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"mb-4"&lt;/span&gt; &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Image Upload&lt;span class="nt"&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"jumbotron"&lt;/span&gt; &lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
                &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"btn btn-primary"&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"file"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"imageUpload"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;h5&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"progessIndicator"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;upload progress: 0%&lt;span class="nt"&gt;&amp;lt;/h5&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"app.js"&lt;/span&gt; &lt;span class="nt"&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  script.js
&lt;/h1&gt;

&lt;p&gt;First, we need to create a storage reference to refer to the storage location. In the code, we can provide content type to upload the exact content to the storage. I have to implement addEventListener to listen to the image changes by the user. Inside the listener function, I used a file variable to get the file i.e image file. With the help of storageRef variable, I am uploading the image to the firebase storage. All the images reside in the child directory named 'images'. And, also progress indicator indicates the current uploading progress in percentage that reflects on the screen.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;firebaseConfig&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;apiKey&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Your API KEY&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;//replace with your key&lt;/span&gt;
  &lt;span class="na"&gt;authDomain&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;image-uploader-a5a2c.firebaseapp.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;databaseURL&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://image-uploader-a5a2c.firebaseio.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;projectId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;image-uploader-a5a2c&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;storageBucket&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;image-uploader-a5a2c.appspot.com&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;messagingSenderId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1016001991019&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;appId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;1:1016001991019:web:9cd7eb0ebfdbea5e45fc2e&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="c1"&gt;// Initialize Firebase&lt;/span&gt;
&lt;span class="nx"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;initializeApp&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;firebaseConfig&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//storage reference&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;storageRef&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;firebase&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nx"&gt;ref&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;imageUploader&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;imageUpload&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;progessIndicator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;progessIndicator&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;//metadata to store specific file type&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;contentType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;image/jpeg&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;//listening the on change image file&lt;/span&gt;
&lt;span class="nx"&gt;imageUploader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;change&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;//holding the img&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;files&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

  &lt;span class="c1"&gt;//uploading the img on firebase storage&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;uploadImage&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;storageRef&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;child&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;images/&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;file&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nx"&gt;uploadImage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;state_changed&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;snapshot&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;progress&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;snapshot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bytesTransferred&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;snapshot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;totalBytes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;progessIndicator&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`upload progress: &lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;progress&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;%`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="/blog-images/firebaseStorage10.png" class="article-body-image-wrapper"&gt;&lt;img src="/blog-images/firebaseStorage10.png" alt="firebase storage 10"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="/blog-images/firebaseStorage3.png" class="article-body-image-wrapper"&gt;&lt;img src="/blog-images/firebaseStorage3.png" alt="firebase storage 3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to know whether the image is uploaded or not?
&lt;/h2&gt;

&lt;p&gt;Go the project main screen, click the storage option(left panel). Now you can see a folder named image and inside the folder, all the images are stored.&lt;br&gt;
&lt;strong&gt;For More Information -&lt;/strong&gt; Click Here &lt;a href="https://firebase.google.com/docs/storage"&gt;Firebase Storage&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
