Fireship · @fireship
Angular Drag-and-Drop File Uploads to Firebase Storage
Uploaded June 24, 2017 · Length 6:15
Summary
build drag and drop file upload feature with angular and firebase storage
- angular
- firebase storage
- drag and drop
- file upload
- angular directive
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:01
in this episode we're going to build a
- 0:03
drag and drop file upload feature that
- 0:05
uploads the file to Firebase
- 0:08
storage there's already several file
- 0:11
upload packages for angular 4 and
- 0:12
angular 2 such as Drop Zone JS and
- 0:15
others but none of them tie in easily
- 0:18
with Firebase storage and it's
- 0:19
relatively straightforward to do the
- 0:21
entire thing from scratch which I'll
- 0:23
show you how to do in this
- 0:25
lesson let's get started by building the
- 0:28
service I have another lesson that goes
- 0:30
through Firebase file uploads in more
- 0:33
detail so for now I'm just going to run
- 0:35
through the bare minimum code that's
- 0:36
needed to get angular working with
- 0:38
Firebase
- 0:39
storage first we Define an upload class
- 0:42
that models the data we want to send to
- 0:44
the
- 0:45
database in this example we build the
- 0:48
object by sending it a Javascript file
- 0:50
object to the
- 0:53
Constructor in the upload service we
- 0:56
import this class as well as the angular
- 0:58
Fire 2 package
- 1:00
and we also need to import the entire
- 1:02
Firebase SDK because file uploads aren't
- 1:05
supported at this point by the angular
- 1:07
Fire 2
- 1:09
package now we create a function to
- 1:11
handle the upload task it's going to use
- 1:14
the Firebase API to create a promise
- 1:17
which we can use to monitor the status
- 1:19
of the upload
- 1:21
itself when the upload task is complete
- 1:24
it'll save some information about the
- 1:25
file to the real-time database most
- 1:27
importantly the download URL which we
- 1:29
can use to access the
- 1:31
[Music]
- 1:36
file now we can start building the
- 1:38
attribute directive in this case we go
- 1:41
with an attribute directive over a
- 1:42
component because the functionality
- 1:45
itself doesn't need an actual HTML
- 1:48
template inside the directive we're
- 1:50
going to use event emitter post listener
- 1:53
and
- 1:54
output we use a combination of output
- 1:57
and event emitter to create our own C


