You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 3, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 3, 2026. It is now read-only.
File.publicUrl() returns an incorrect URL if the file key contains URL query parameters #1824
Upload a file to Cloud Storage containing query parameters in the key -- example: somefile.jpg?state=thumbnail
Make the file public via File.makePublic()
Retrieve the file's public URL with File.publicUrl()
The returned URL looks like https://storage.googleapis.com/bucket/somefile?state=thumbnail but any attempt to download the file at that URL results in the following error:
<Error>
<Code>AccessDenied</Code>
<Message>Access denied.</Message>
<Details>Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.</Details>
</Error>
HOWEVER Viewing the file in the Google Cloud Platform Cloud Storage web console does give the correctly-encoded URL which looks like https://storage.googleapis.com/bucket/somefile.jpg%3Fstate%3Dthumbnail
I've reviewed the Changelog for subsequent releases but there is no mention of a fix for this.
Thank you for bringing this to our attention @jbrowning. I have identified what I believe to be the source of the problem you are encountering and will be working on a fix. I will update this issue soon with any further findings / when a fix is available.
@ddelgrosso1 was it intentional that filenames with paths now turn from upload/video/test.mp4 to upload%2Fvideo%2Ftest.mp4?
It still works, and the GCS UI shows the directories as expected, but the public urls I store in my DB are less readable.
Hi @sseppola it was intentional from the standpoint that other spots in the code are currently encoding the entire name portion as I applied in the fix. Your suggestion makes sense to me, let me investigate if switching to something like this will have any other possible consequences.
@sseppola I should have realized this before but the reason it was done this way is due to the object naming guidelines in GCS. In the above snippet this.name represents the object name, which can support characters such as spaces, ampersands, etc. In order to return a properly working public url the entire name will need to be encoded to account for these cases.
Activity
ddelgrosso1 commentedon Mar 28, 2022
Thank you for bringing this to our attention @jbrowning. I have identified what I believe to be the source of the problem you are encountering and will be working on a fix. I will update this issue soon with any further findings / when a fix is available.
ddelgrosso1 commentedon Mar 28, 2022
@jbrowning what I believe to be the fix for this has been released in version
5.18.3.jbrowning commentedon Mar 28, 2022
@ddelgrosso1 Perfect. Thanks for the quick fix.
sseppola commentedon Apr 7, 2022
@ddelgrosso1 was it intentional that filenames with paths now turn from
upload/video/test.mp4toupload%2Fvideo%2Ftest.mp4?It still works, and the GCS UI shows the directories as expected, but the public urls I store in my DB are less readable.
Edit:
Would you consider something like:
This should be Nodejs 10 compatible according to: https://developer.mozilla.org/en-US/docs/Web/API/URL
ddelgrosso1 commentedon Apr 7, 2022
Hi @sseppola it was intentional from the standpoint that other spots in the code are currently encoding the entire name portion as I applied in the fix. Your suggestion makes sense to me, let me investigate if switching to something like this will have any other possible consequences.
ddelgrosso1 commentedon Apr 7, 2022
@sseppola I should have realized this before but the reason it was done this way is due to the object naming guidelines in GCS. In the above snippet
this.namerepresents the object name, which can support characters such as spaces, ampersands, etc. In order to return a properly working public url the entire name will need to be encoded to account for these cases.sseppola commentedon Apr 7, 2022
Makes sense, thanks for resolving it so quickly 👍