Firebase Cloud Storage
In this guide, you’ll learn how to use Firebase Storage to upload the pictures. Cloud Storage is a beautiful API because it lets you supercharge your application.
Instead of just text in the database, you can also store files like images, PDFs, documents, etc.
The first thing you need to do is to import the storage instance and add it to the constructor:
Then, you can create your function to upload the picture, create a function that receives the
base64
string as a parameter:
After we have our function, let’s create a reference to where we’ll put our file:
After we create the reference, we need to upload the picture to Storage:
And that’s it. We uploaded our picture to Cloud Storage, but what if we want to use that picture?
All we need to do is to get the picture’s downloadURL, then we can use it as we want, for that we can do this:
And now you can use that downloadURL anywhere you want, for example, if you want to show the profile
picture on the website you can use the <img>
tag like this: