Skip to content

Firestorage has different behavior when hardcode

I don’t know what happened with my code. But everytime i used this code is working

const downloadUrlThumb = async(urlPathThumbs) => {
        const gsRef = projectStorage.refFromURL('gs://') // hardcode mode
        //const gsRef = projectStorage.refFromURL(urlPathThumbs)
        await gsRef.getDownloadURL().then(urlDownload => {
            console.log('URL THUMB ADALAH: ', urlDownload);
            url.value = urlDownload

        }).catch(err => {

But when i switched to urlPathThumbs it will become error 404. Error said like so

Firebase Storage: Object ‘courses/m9APF8TEUnfS6IQew591sl4kphH2/thumbs/Rectangle 68 (1)_200x200.png’ does not exist. (storage/object-not-found)

however they both are same pattern. This is how variable urlPathThumbs created in previous snippet code

var filename =[wd_-]+)$/i, '_200x200$1')
            console.log('filename ', filename);
            let location = 'gs://'+user.value.uid+'/thumbs/'+filename
            console.log('full location: ', location); // --> This will print full location:  gs:// 68 (1)_200x200.png
            await downloadUrlThumb(location)

this file is successful uploaded and i can see it in firebase storage location: firebase storage

Please can somebody help me?



since refFromURL is expecting a URL string, spaces should not be allow. You will need to urlencode the spaces.


console.log(encodeURI("gs:// 68 (1)_200x200.png"))

refFromURL refFromURL ( url : string ) : Reference Returns a reference for the given absolute URL.

Parameters url: string A URL in the form: 1) a gs:// URL, for example gs://bucket/files/image.png 2) a download URL taken from object metadata. @see