Firebase Storage — Flutter

Firebase Storage — Flutter 💙💛

Storing images and files to your server is a hectic task. But Firebase Storage has solved this problem to a great extent! Let’s see how we can use it!

Firebase is one of the services that provide many functionalities that you can use in your web and mobile applications! Initially, when we wanted to store images and files in our database, it was a hectic task! Firebase Storage is a service that allows you to store files and images into cloud storage with ease and significantly less amount of code!

To start with Firebase Storage, there are the following steps involved:

  • Enable storage from the console.
  • Create code for different operations of storage.

https://medium.com/media/ceb4fd2380af661521a6e88c61bea3a3/href

Step 1: Enable Storage from the Console

Go to the Firebase Console and open your project. On the right panel, click on the Storage option, and it will bring you to a welcome/introduction page where you can click on Get Started button! Follow the next steps and enable the Firebase Storage.

Step 2: Upload Files to Storage

Firebase Storage code is really short and easy to do. Let’s see how you can add an upload operation for Firebase Storage!

https://medium.com/media/d5eb1f5c4a7e13a87e913ed3daf4363f/href

You can upload a file in either way:

  • Uint8List
  • From a path
  • From a local file

Here, we have uploaded the image in form of Uint8List! You can see the code is just 1 line and this will upload the file with the provided file name to your storage bucket!

Step 3: Get the Download URL

Once the image is uploaded, you can get the download URL of that image so that you can use NetworkImage to show the particular image.

https://medium.com/media/434e19727b563a14abfd027a4cd136f6/href

Step 4: Delete the file

Well, keeping unwanted files in storage would be useless. It’s always a good practice to delete the file when the user is deleted.

https://medium.com/media/101762329d2e500683a84b2cd1a2fa27/href

So, your entire service file would look like the following:

https://medium.com/media/7ccbaa062b39dd252b21cd900becf450/href

And that’s it!!!

https://medium.com/media/6b8748a5940ad1106b62d695c607596e/href

Hope you enjoyed this article!

Feel free to try it yourself by cloning the GitHub Repository!

Doubts? Feel free to drop a message @AbhishekDoshi26

Don’t stop, until you are breathing!💙
– Abhishek Doshi


Firebase Storage — Flutter 💙💛 was originally published in Google Developers Experts on Medium, where people are continuing the conversation by highlighting and responding to this story.

Total
1
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
what’s-the-shape-up-methodology-and-how-to-use-it-to-build-meaningful-products

What’s the Shape Up Methodology and How to Use it To Build Meaningful Products

Next Post
google-workplace-gde-alice-keeler-on-balancing-responsibilities-and-using-coding-as-self-care

Google Workplace GDE Alice Keeler on balancing responsibilities and using coding as self-care

Related Posts