question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

File.publicUrl() returns an incorrect URL if the file key contains URL query parameters

See original GitHub issue

Environment details

  • OS: Google Cloud Function (1st gen)
  • Node.js version: 14.19.1
  • npm version:
  • @google-cloud/storage version: 5.8.5

Steps to reproduce

  1. Upload a file to Cloud Storage containing query parameters in the key – example: somefile.jpg?state=thumbnail
  2. Make the file public via File.makePublic()
  3. 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.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ddelgrosso1commented, 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.

0reactions
sseppolacommented, Apr 7, 2022

Makes sense, thanks for resolving it so quickly 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Beginner's Guide to URL Parameters - Semrush
In this comprehensive guide, we explore the ins and outs of URL parameters. Discover now how to use query strings without hurting your ......
Read more >
Google Cloud Storage public link does not become invalid ...
When Your sharing Publicly Url is like https://storage.googleapis.com/bucket_name/pictureName. If you delete the file or uncheck the Share ...
Read more >
Filter a report using query string parameters in the URL
You want to create a report that has links to other Power BI reports, but you want to show only some of the...
Read more >
A guide to Firebase Storage download URLs and tokens
A Firebase download URL is a long-lived, publicly accessible URL that is used to access a file from Cloud Storage. The download URL...
Read more >
About URL parameters - Google Ads Help
URL parameter is a way to pass information about a click through its URL. You can insert URL parameters into your URLs so...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found