toljoas
toljoas

Reputation: 37

GCP cloud storage get downloadable url

I have a public bucket, that I use to host public user content.

I want to give users the ability to download those files, by clicking a link, which opens the gcp page, that starts the download automatically. For this the content-disposition header needs to be set.

I would also like to set the filename of the downloaded file.

Is there a way to handle this within gcp?

I know I could generate a signed url: Google Cloud Storage: download a file with a different name, and set the desired headers, but I don't think this is the proper solution. From my understanding signed urls should be used, when accessing protected resources. Is there a way to get the download link easily?

I currently handle this on my own server, but I would like to let gcp handle it. Here is a demo url of a cloud file: https://storage.googleapis.com/just-demo-bucket-14512/Big_Buck_Bunny_1080_10s_5MB.mp4

router.get('/download', (req, res) => {
    res.setHeader("content-disposition", "attachment; filename=cool.mp4");
    request('https://storage.googleapis.com/just-demo-bucket-14512/Big_Buck_Bunny_1080_10s_5MB.mp4').pipe(res);
})

Upvotes: 0

Views: 1254

Answers (1)

Antonio Ramirez
Antonio Ramirez

Reputation: 1058

If you want to set the content-disposition header on the fly, in other words:

https://storage.googleapis.com/path/to/file?content-disposition=... 

Then the answer is No; you cannot do this.

If you want a static content disposition, you can use the header of Cloud Storage but if you want something dynamic, you have to put a server in front of it.

However, if you feel strongly that this must be handled by the Cloud Storage API, you may raise a feature request by specifying how this should be implemented and the added value it would have.

Upvotes: 1

Related Questions