0

After generated downloadURL in firebase using:

{ 
 ... 

 let url = uploadTask.snapshot.downloadURL;

 ...
}

the url content is something similar:

https://firebasestorage.googleapis.com/v0/b/sd2ds-.23.appspot.com/o/Usr%2FEls%2 ...

No worries in using in the browser or HTML tags, however, when I try to use the url generated in photoURL an error is generated:

The photoURL field must be a valid URL.

I already tried use decodeURI(url) but nothing changed.

Firebase generates the url with %2 in / (slash) place and seems be the problem.

Any glue?

Thanks

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Mario
  • 847
  • 1
  • 8
  • 13
  • **decodeURI(url)** did not work correctly, however, **decodeURIComponent(url)** worked perfectly removing all %2 %20 etc... A kind of workaround... – Mario Jul 26 '17 at 17:13

1 Answers1

0

Use decodeURIComponent.

Suggestion of function with error handling:

const validUrl     = require('valid-url');

const fillPhotoUrl = function(p) { return (p && validUrl.isUri(p)) ? decodeURIComponent(p) : null; };

Then use it:

{ 
 ... 

 let url = fillPhotoUrl(uploadTask.snapshot.downloadURL);

 ...
}

If you want to know the difference between decodeURI and decodeURIComponent, see this question.

Vitor Mori
  • 83
  • 1
  • 5