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.

Allow forcing a file to download instead of opening in the browser

See original GitHub issue

Feature 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:

  1. 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)
  2. 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
    1. 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

  1. 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).
  2. 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
  3. 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
thebengeucommented, Mar 10, 2022

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.

1reaction
fenoscommented, Sep 29, 2022

PR is up - this feature will land shortly! 🎉

Read more comments on GitHub >

github_iconTop 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 >

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