Search code examples
swiftfirebasefirebase-storagefirebase-security

How to remove query string from Firebase Storage download URL


Problem:

I need to be able to remove all link decoration from the download URL that is generated for images in Firebase Storage. However, when all link decoration is stripped away, the resulting link currently would return a JSON document of the image's metadata.

Context:

The flow goes as follows:

An image is uploaded to Firebase from an iOS app. Once that is done the download URL is then sent in a POST request to an external server.

The server that the URL is being sent to doesn't accept link decoration when submitting image URLs.

Goal:

Alter the Firebase Storage download URL such as it is stripped of all link decoration like so:

Notes:

The problem is twofold really, first the link needs to be manipulated to remove all the link decoration. Then the behavior of the link needs to changed, since in order to return an image, you need ?alt=media following the file extension, in this case .jpg. Currently, without link decoration, using the link with my desired structure would return a JSON document of the metadata.

The current link structure is as follows:

Desired link structure:

The token is necessary for accessing the image depending security rules in place, but can be ignored with the proper read permissions. I can adjust the rules as needed, but I still need to be able to remove the ?alt=media and still return an image.


Solution

  • Building up on Frank's answer, if you access to your associated Google Cloud Platform project, find the bucket in the Storage tab and make this bucket public, you will be able to get the image from here with the format you wish. That is, you will not be accessing through Firebase

    https://firebasestorage.googleapis.com/v0/b/example.appspot.com/o/[FOLDER_NAME]%[IMAGE_NAME].jpg

    but through Google Cloud Storage, with a link like

    https://storage.googleapis.com/[bucket_name]/[path_to_image]

    Once in your GCP project Console, access the Storage bucket with the same name as the one you have in your Firebase project. They are the same bucket. Then make the bucket public by following these steps. After that, you will be able to construct your links as mentioned above and they will be accessible with no token and no alt=media param. If you do not want to make the public to everyone, you will be able to play around with the permissions there as you wish.