Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70434

Firebase photo URL

$
0
0

@flosrn wrote:

I want to upload and load photo from camera or gallery in my ionic app but Ihave problems with the firebase URL…

 uploadPhoto(sType) {
    const options: CameraOptions = {
      quality: 100,
      targetWidth: 720,
      targetHeight: 720,
      sourceType: sType,
      correctOrientation: true,
      destinationType: this.camera.DestinationType.DATA_URL,
      encodingType: this.camera.EncodingType.JPEG,
      mediaType: this.camera.MediaType.PICTURE,
    }
    this.camera.getPicture(options)
    .then(data => {
      const image = `data:image/jpef;base64,${data}`;
      var randomNumber = Math.floor(Math.random() * 256);
      const userPic = firebase.storage().ref('/requests/' + randomNumber);
      userPic.putString(image, 'data_url')
      .then(()=> {
        this.loadPhoto();
      })

    })
    .catch(error => {
      console.log(error);
    })
  }

  loadPhoto(){
    const loading = this.loadingCtrl.create({
      content: 'Chargement en cours...'
    });
    loading.present();
    var randomNumber = Math.floor(Math.random() * 256);
    const userPic = firebase.storage().ref('/requests/' + randomNumber);
    userPic.getDownloadURL()
    .then((url)=> {
      this.pic = url;
      this.request.photo   = url;
      loading.dismiss();
    })
    .catch(e =>{
      const userPic = firebase.storage().ref('requests/default.jpg');
      userPic.getDownloadURL().then((url)=> {
        this.pic = url;
        console.log('this PIC ====' +this.pic);
        loading.dismiss();
      })
    });
  }

When I put in the url just “/requests/aaa.jpg” it work perfectly, but when I put a random number, dateTime() or other else it did’nt work…

I would like a different name for each photo uploaded, how please ?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70434

Trending Articles