繁体   English   中英

我无法从Firebase Storage(Angular / Ionic)获取图像downloadUrl

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

我正在尝试从firebase获取图像的downloadUrl,所有属性,例如'timeCreated','fullPath','contentType'均正常运行并正确推送! 但我不知道为什么“ downloadUrl”不起作用!

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

    });
  }

数据提供者:

storeImageInformation(downloadURL)
 {
this.db.list(`/profiles/${this.afAuth.auth.currentUser.uid}`).
push(downloadURL); 
      }

有什么想法吗?!

THX Doug,你是对的。

正确的代码是这样的:

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

  upload.then().then(res => {
    this.data.storeImageInformation(res);
  }); 
}

数据提供者:

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}); }

现在,在立即上传的结果中不再可以访问下载URL。 几个月前,Firebase客户端SDK进行了此更改。

取而代之的是,您必须调用getDownloadURL (或该JavaScript函数的任何Angular绑定),以在完成上传后将URL作为第二个请求。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM