1

I have assets from Wordpress being uploaded to GCP Storage bucket. But when I then list all these links to these assets within the website im working on, I would like the user to automatically download the file instead of viewing it in the browser when the user clicks on the link.

Is there an "easy" way to implement this behaviour? The project is running with Wordpress as headless API, and Next.js frontend.

Thanks

nickelman
  • 702
  • 6
  • 24

1 Answers1

0

You can change object metadata for your objects in Cloud Storage to force browsers to download files directly, instead of previewing them. You can do this through the available content-disposition property. Setting this property to attachment will allow you to directly download the content.

I quickly tested downloading public objects with and without this property and can confirm the behavior, downloads do happen directly. The documentation explains how to quickly change the metadata for existing objects in your bucket. While it is not directly mentioned, you can use wildcards to apply metadata changes to multiple objects at the same time. For example this command will apply the content-disposition property in all objects of the bucket:

gsutil setmeta -h "content-disposition:attachment" gs://BUCKET_NAME/**
ErnestoC
  • 2,660
  • 1
  • 6
  • 19