Allow forcing a file to download instead of opening in the browser
See original GitHub issueFeature request
Is your feature request related to a problem? Please describe.
I have json files uploaded in supabase storage and I provide presigned links to them in <a>
tags in my webapp. Currently, when users click on these links, they are navigated to the json file, which displays in the browser. I would prefer clicking on the link to instead pop up a “Download file” prompt and leave the user on the same page (i.e. don’t navigate away), so that downloading json files behaves the same as downloading other files.
Describe the solution you’d like
I think there are 2 options that might make sense:
- Accept a
Content-Disposition
header when uploading a file to storage-api (pass it through to the S3/File backends similar to the Content-Type header) - Allow a
Content-Disposition
header to be provided when creating a presigned url, that header is then included in the response when a client follows the presigned url- This option is similar to how the AWS SDK allows you to override a variety of different headers for presigned urls, see the Overriding Response Header Values heading in the docs
Describe alternatives you’ve considered
- Using the
download
attribute on anchor tags (<a>
) doesn’t work, because my webapp is on a different domain/origin than the storage-api/kong (which is on a supabase.co subdomain). - You can get around the above same-origin limitation by downloading as a
blob:
URL, but that’s clunky and slow and restrictive. Source: https://stackoverflow.com/a/49500465 - I could upload files with a bogus content type (e.g.
application/octet-stream
), so they would be served back with the same content type header and the browser wouldn’t think it could open it directly. But, this seems hacky.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
6 Ways to Force Download Instead of Opening File in Browser
All you need to do is group your desired files into a folder on your device. After that, you right-click that folder and...
Read more >Force a File to Download Instead of Opening it in a Browser ...
A special download attribute can be used inside of an <a href> tag that will tell the browser to download the file instead...
Read more >How to force to download files instead opening in the browser?
Go to Library settings > Advanced Settings, you will find the option under the "Opening Documents in the Browser" section.
Read more >How do I force files to open in the browser instead of ...
Browser tries to open it: use header("Content-Disposition", "inline; filename=myfilename.myextension");. No control over the server code: Use the HTML5 download ...
Read more >How do I force a file to open in a browser instead of download?
In the browser, press the Ctrl + O keys and select the desired file.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the detailed feature request. I think that it might make sense to support both options, just like how the AWS SDK does. I’d probably be able to get to this in early April.
PR is up - this feature will land shortly! 🎉