Upload file to firebase -- FileChooser


#1

Hi i want to upload a file of any type (img, txt, pdf …etc) to firebase, i’am using FileChooser to get the file URI, but to upload the file to firebase i need the file not the URI, if i got the file i can use the put(file) function. My question is how do i get file from the file URI? :

this is the code to get the URI:
FileChooser.open().then(uri=>{
console.log(“uri:”, uri);
this.presentToast(uri);
}).catch(error => {
console.error(error);
this.presentToast(error);
});

this is the code to upload a file to firebase storage :

var uploadTask = this.storage.child(auth.uid+'/'+file.name)
    .put(file);

    uploadTask.on('state_changed',
    (snapshot)=>{
      console.log("subiendo");
    },
    (error)=>{
      console.error(error);
    },()=>{
      console.log("Successsss");
      console.log(uploadTask.snapshot.downloadURL);
    });

#2

Hey, I made a topic that answers your question. (I saw your question after uploading lol)

It works on Ionic 2 and 3