Why the slashes in the URL of my Cloud Storage need to be encoded as %2F?

Viewed 870

I have a file stored in the following folder of my Firebase Cloud Storage:

/logs/2021/03/2021-03-22.json

And I'm trying to access it through a download URL.

This does not work:

https://firebasestorage.googleapis.com/v0/b/PROJECT_ID.appspot.com/o/logs/2021/03/2021-03-22.json?alt=media

I get this error when I try to open the file with the URL above:

{
  "error": {
    "code": 400,
    "message": "Invalid HTTP method/URL pair."
  }
}

But the following URL works fine (when the slashes from the folder path are encoded as %2F), and I get the contents of the file as expected.

https://firebasestorage.googleapis.com/v0/b/PROJECT_ID.appspot.com/o/logs%2F2021%2F03%2F2021-03-22.json?alt=media

Why is that? Will I always need to encode the slashes from the bucket's folder levels as %2F ?

1 Answers

The character / works as a path separator of individual elements of your URL, and %2F is converted into a /, then working as a separator in your URI.

Related to the question: a % sign always indicates an encoded character, a URI may be made "safer" simply by encoding any characters considered unsafe, while leaving already encoded characters still encoded [1].

Talking about Firebase, Google documentation says: The part of the log name following /logs/ must be URL-encoded. This means that the forward-slash character, /, must be written as %2F [2].

[1] https://www.w3.org/Addressing/URL/4_URI_Recommentations.html

[2] https://firebase.google.com/support/guides/cloud-audit-logging/firebase-management

Related