Upload Image Ionic 3


#1

How to do to upload image in Storage and add in item in Database

my upload.service.ts

  save(fileUpload: FileUpload) {
    const storageRef = firebase.storage().ref();
    let uploadTask = storageRef.child(`${this.PATH}/${fileUpload.file.name}`).put(fileUpload.file);
    uploadTask.on(firebase.storage.TaskEvent.STATE_CHANGED, (snapshot) => {
      fileUpload.progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100
    }, (error) => {
      console.log(error)
    }, () => {
      fileUpload.url = uploadTask.snapshot.downloadURL
      fileUpload.name = fileUpload.file.name
      console.log(fileUpload.url)
      this.saveFileData(fileUpload);
    })
  }

  private saveFileData(upload: Upload) {
    this.db.list(`${this.PATH}/`).push(upload);
  }

#2

This blog post from Clearly Innovative will show you how take a photo, make into a blob, upload the file to firebase storage, then save a reference in the firebase database.
http://www.clearlyinnovative.com/ionic-firebase-and-image-upload-revisited-sorry-android-users?utm_content=bufferad8d3&utm_medium=social&utm_source=twitter.com&utm_campaign=buffer


#3

You must memorize on the database the “downloadURL” field that represents the path of the image!