Angular 6 Firebase – Upload/Display/Delete Files from Storage

In the post, we have known how to upload file to Firebase Storage. This tutorial shows you way to upload, get, delete Files in a simple Angular 6 App.

I. Technology

– Angular 6
– AngularFire2 5.0

II. How to do

1. Set up the Firebase Project & Install AngularFire2

Please visit this post to know step by step.

2. Upload File Service

– upload file to Storage and file’s info to Database.
– get List Files from Firebase Storage by files’info (name/url) stored in Database.
– delete file with 2 steps: delete file’s info from Database, then delete file from Storage

To know how to save file info to Firebase Realtime Database, please visit previous post:
Angular 4 Firebase – Upload File to Storage

3. Get and display List of Files

HTML template:

III. Practice

1. Project Overview
1.1 Goal

We will build an Angular 6 Firebase App that can:
– helps user choose file from local and upload it to Firebase Storage
– show progress with percentage
– save file metadata to Firebase Realtime Database
(Functions above from the posts: Angular 4 Firebase – Upload File to Storage)
– get list Files and display

angular-6-firebase-storage-tutorial-upload-get-files-storage-result

1.2 Structure

angular-6-firebase-storage-tutorial-upload-get-files-storage-project-structure

2. Step by step
2.1 Set up the Firebase Project & Install AngularFire2

Please visit this post to know step by step.

*Note: Don’t forget to set RULES for public read/write Database and Storage.

angular-6-firebase-storage-tutorial-upload-get-files-storage-rules

2.2 Add Firebase config to environments variable

Open /src/environments/environment.ts, add your Firebase configuration that we have saved when Popup window was shown:

2.3 Create Service & Components

Run the commands below:
ng g s upload/UploadFile
ng g c upload/FormUpload
ng g c upload/ListUpload
ng g c upload/DetailsUpload

2.4 Setup @NgModule

app.module.ts

2.5 Model Class

fileupload.ts

2.6 Service

upload-file.service.ts

2.7 Form Upload Compoment

form-upload.component.ts

form-upload.component.html:

2.8 DetailsUpload Component

details-upload.component.ts

details-upload.component.html

2.9 ListUpload Component

list-upload.component.ts

list-upload.component.html

2.10 App Component

app.component.ts

app.component.html

2.11 Check Result

Run the App, go to http://localhost:4200/.

angular-6-firebase-storage-tutorial-upload-get-files-storage-result

Check Firebase Console:
– Database:

angular-6-firebase-storage-tutorial-upload-get-files-storage-database-result

– Storage:

angular-6-firebase-storage-tutorial-upload-get-files-storage-storage-result

IV. Source Code

Angular6FirebaseStorage-files

By grokonez | June 19, 2018.



Related Posts


1 thought on “Angular 6 Firebase – Upload/Display/Delete Files from Storage”

Got Something To Say:

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

*