Select and Upload Files to Firebase Storage

Mercy Jemosop
2 min readSep 2, 2021

Add files and images to Firebase storage

Introduction

Cloud Storage is designed to help you quickly and easily store and serve user-generated content, such as photos and videos.

Firebase storage dependency. Add the dependency to your pubspec.yaml file. Check the latest version here.

dependencies:
flutter:
sdk: flutter
firebase_core: "^1.5.0"
firebase_storage: "^10.0.2"

Before we start using Storage we must first ensure we have initialized FlutterFire. This is usually done before any Firebase service is used. This step is asynchronous meaning flutterfire usage is prevented until initialization is complete.

await Firebase.initializeApp();

The initializeApp() method is asynchronous and returns a future. Update your main flutter function

N.B You can change the rules on your storage to allow a user who is not signed in to upload files.

Now let’s create a new dart file to upload our files to storage

Step 1: import cloud storage package to our project.

import 'package:firebase_storage/firebase_storage.dart' as firebase_storage;

Step 2:Create a storage instance by calling the instance getter on Firebase Storage.

firebase_storage.FirebaseStorage storage =
firebase_storage.FirebaseStorage.instance;

Step 3: Select file from local storage. Add the file_picker and path dependency to your pubspec.yaml file.

To select file from local storage, Add the file_picker and path dependency to your pubspec.yaml file.

file_picker: ^4.0.1
path: ^1.8.0

Upload the selected image to cloud storage

Happy coding!!!!!!!!!!!!!!!!!!!!!!!!!!

--

--

Mercy Jemosop

Software Developer. I am open to job referrals. connect with me on twitter @kipyegon_mercy