Question

I'm wondering if it's possible to download a file from Google Cloud Storage with a different name than the one that has in the bucket.

For example, in Google Cloud Storage I have stored a file named 123-file.txt but when I download it I would like choose a different name, let's say file.txt

I've noticed that the link for download it is like: https://storage.cloud.google.com/bucket_name%2F123-file.txt?response-content-disposition=attachment;%20filename=123-file.txt

So I've tried to change it to: https://storage.cloud.google.com/bucket_name%2F123-file.txt?response-content-disposition=attachment;%20filename=file.txt

But it still keeps downloading as 123-file.txt instead of file.txt

Was it helpful?

Solution

The response-content-disposition parameter can only be used by authorized requests. Anonymous links don't work with it. You have a few options:

  1. The content-disposition of a particular object is part of its metadata and can be permanently set. If you always want a specific file to be downloaded with a specific name, you can just permanently set the content-disposition metadata for the object.

  2. You can also generate signed URLs that include the response-content-disposition query parameter. Then the users will be making authorized requests to download the resource.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top