Get non-percent encoded URL from firebase storage

Viewed 186

Using .getDownloadURL() is giving me percentage encoded URLs from Firebase Storage. In this case I want to upload a file to the subfolder "images". Here is the upload code.

          var metadata = {
            contentType: "image/jpeg",
          };

          var imagesRef = storageRef.child("images");

          var fileName = image.jpg;
          var singleImageRef = imagesRef.child(fileName);

          var path = singleImageRef.fullPath;
          var uploadTask = storageRef
            .child(path)
            .put(fileName, metadata);

The URL returned looks like this: https://firebasestorage.googleapis.com/v0/b/app-name.appspot.com/o/images%2Fimage.jpg?alt=media&token=tokenstring

Which works - I'm taken to the correct image. But I want the URL to read: https://firebasestorage.googleapis.com/v0/b/app-name.appspot.com/o/images/image.jpg?alt=media&token=tokenstring

Is there some metadata I should be passing on upload to stop the percentage encoding happening?

1 Answers

You can't control the download URLs that Firebase Storage generates. You'll have to treat them as opaque strings that reference the file.

If you want control of the URLs of your files, you will have to set up your own file server, or a custom API that acts as a proxy for the files in Cloud Storage.

Related