Upload Multiple Images to Firebase Storage And GetDownload URL


#1

Im Using Ionic Image Picker(Native) to Get Multiple Images to an array.in array file look like this

file:///data/user/0/io.ionic.starter/cache/tmp_IMG_20180520_182034263619941.jpg

My ionic Image Picker Code is Here

getImages(){
let option = {
  title:"Selec Your Images",
  message:'You can only select 5 Images',
  maximumImagesCount:5,
  outType:1
}
this.imgPicker.getPictures(option).then((results) => {

for(let i=0; i < results.length;i++){
       console.log(results[i]);
       this.images[i]=results[i];
  };
 },(err)=> {
  console.log("Get Image faild");
})

I Use This Method To Upload File and Get the Download URL But it Didn’t Work.Even File Not Uploaded To The Firabase Storage.

 if(this.images.length > 0){
    for (var i=0; i<this.images.length; i++) {
       firebase.storage().ref('/images').putString(this.images[i], 'data_url',{contentType: 'image/jpg'}).then((data)=>{
        this.userPost.photos[i]=data.downloadURL
       console.log( 'this is download url '+this.userPost.photos[i]);
      })
    }
  }

Im Stuck In This Problem Long Time.


#2

I have exactly the same issue did you manage to resolve this?


#3

Hello :slight_smile:

Your code is neat, i use a kind of same function but only locally on the smartphone, with an automated backup on cloud.

Beware that this.images.length may not be an array and as a result, can crash your script.

Also, this.imgPicker refers to something quite ugly in terms of UX, I mean the old HTML select, i hope you’re not coding upon this :D.

Have fun with Ionic ;:slight_smile: