3
votes

I am trying to get the download url of an image right after I upload it, my code looks like this:

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

The error is:

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

Is there something wrong with how I am getting the download url? Thanks.

1
yah thanks for the helpewizard

1 Answers

1
votes

You should not pass a callback-function to getDownloadURL, since it takes no arguments. It returns a Promise containing the URL. The URL is accessible when the Promise resolves, in .then(url => {}).

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