Firebase存储:`getDownloadURL`中的参数计数无效:预期的0个参数,收到1

时间:2017-07-31 20:04:39

标签: angular url firebase ionic-framework firebase-storage

我试图在上传后立即获取图片的下载网址,我的代码如下:

    let image       : string  = 'promo_' + this.username + '_' + new Date() + '.png',
      storageRef  : any,
      parseUpload : any;

    return new Promise((resolve, reject) => {

      storageRef       = firebase.storage().ref('/promos/' + image);
      parseUpload      = storageRef.putString(this.imageHolder, 'data_url');

      parseUpload.on('state_changed', (_snapshot) => {
          // We could log the progress here IF necessary
          console.log('snapshot progess ' + _snapshot);
        },
        (_err) => {
           reject(_err);
           console.log(_err.messsage);
        },
        (success) => {
           resolve(parseUpload.snapshot); 
        })
      }).then(value => {

          storageRef.getDownloadURL(url => {
          this.list = this.af.list('/promos');
          this.list.subscribe(items => {
            let metadata = {
              customMetadata: {
                'title': this.item.title,
                'caption': this.item.caption,
                'price': this.item.price,
                'date': this.item.date,
                'typeofselect': this.item.typeofselect,
                'username': this.username,
                'url': url
              }
            }
            items.push(metadata);
          })
        }).catch(e => console.log(e.message);

      }).catch(function(error) {
        console.log(error.message);
      });

错误是:

Firebase Storage: Invalid argument count in 'getDownloadURL': Expected 0 arguments, received 1

我是如何获取下载网址的?感谢。

1 个答案:

答案 0 :(得分:1)

你不应该将回调函数传递给getDownloadURL,因为它不需要参数。它返回包含URL的PromisePromise结算后,.then(url => {})中可以访问该网址。

storageRef.getDownloadURL()
.then(url => {
    // Do something...
});