I can't get image downloadUrl from Firebase Storage (Angular/Ionic)

前端 未结 2 1157
无人及你
无人及你 2021-01-28 09:31

I\'m trying to get downloadUrl for an image from firebase, All properties like \'timeCreated\', \'fullPath\', \'contentType\' are working well & pushed correctly! but I don\

相关标签:
2条回答
  • 2021-01-28 10:05

    THX Doug, you're right.

    The correct code is like this:

    captureAndUpload() {
    this.data.captureImage().then(data => {
      let upload = this.data.uploadImage(data);
    
      upload.then().then(res => {
        this.data.storeImageInformation(res);
      }); 
    }
    

    Data Provider:

    uploadImage(image) {
    
    let storageRef: AngularFireStorageReference;
    
    let newName = `${new Date().getTime()}-${this.afAuth.auth.currentUser.uid}.png`;
    
    storageRef = this.afStorage.ref(`/images/${this.afAuth.auth.currentUser.uid}/${newName}`);
    
    return storageRef.putString(image, 'base64', { contentType: 'image/png'})
              .snapshotChanges().toPromise().then(_ =>
                 {
                  return storageRef.getDownloadURL().toPromise().then(res => {
                    console.log('URL: ', res);
                    return res;
                  });
                }
              ) 
            }
    
     storeImageInformation(downloadURL) {
      return this.db.object(`/images/${this.afAuth.auth.currentUser.uid}`).update({img: downloadURL}); }
    
    0 讨论(0)
  • 2021-01-28 10:12

    The download URL is now no longer accessible in the immediate results of the upload. This change was made a few months ago to the Firebase client SDKs.

    Instead, you will have to call getDownloadURL (or whatever the Angular binding is for that JavaScript function) to get the URL as a second request after the upload is complete.

    0 讨论(0)
提交回复
热议问题