Fireship · @fireship

Upload Files from Angular to Firebase Storage

Uploaded April 19, 2017 · Length 4:02

Upload Files from Angular to Firebase Storage

Summary

Implement file uploads with Angular and Firebase Storage using the Firebase web API.

  • angular firebase storage
  • file uploads angular
  • firebase storage upload

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    in this episode we're going to implement

  2. 0:03

    file uploads with angular and Firebase

  3. 0:05

    storage file storage is currently UNS

  4. 0:08

    supported in the angular Fire 2 package

  5. 0:10

    but it's still possible to use Firebase

  6. 0:12

    storage by inter interacting directly

  7. 0:14

    with the Firebase web API we're still

  8. 0:17

    going to use angular Fire 2 for saving

  9. 0:19

    information about file uploads to the

  10. 0:21

    real-time database such as the files

  11. 0:23

    name and its URL

  12. 0:28

    location the structure this feature is

  13. 0:30

    very similar to the angular Firebase

  14. 0:33

    crud lesson so make sure to check that

  15. 0:35

    out also it's basically just a form that

  16. 0:38

    accepts files uploads them to a storage

  17. 0:40

    bucket then renders the details to a

  18. 0:45

    list the upload class will be used by

  19. 0:47

    the service notice it has a Constructor

  20. 0:50

    for the file attribute which has a class

  21. 0:52

    type of file this class is built into

  22. 0:55

    JavaScript and it defines files that are

  23. 0:57

    passed via HTML form in

  24. 1:02

    inputs the service needs to upload the

  25. 1:05

    file to file based storage then save the

  26. 1:07

    details about the file to the real-time

  27. 1:09

    database first let's add the necessary

  28. 1:12

    Imports including the Firebase

  29. 1:16

    API here's how the push upload function

  30. 1:19

    Works step by step first establish a

  31. 1:22

    reference to the Firebase storage bucket

  32. 1:25

    second Define the upload task as a

  33. 1:28

    promise to put the file F in

  34. 1:31

    storage third monitor the upload task

  35. 1:34

    event using the on

  36. 1:36

    function and last we'll handle the

  37. 1:39

    events of in progress success and

  38. 1:45

    error when the upload is in progress we

  39. 1:48

    will take a snapshot to get the number

  40. 1:49

    of bytes transferred using some simple

  41. 1:52

    math we convert this to a percentage to

  42. 1:54

    display a progress bar for the end user

  43. 1:57

    when the upload is complete we just do a