storage icon indicating copy to clipboard operation
storage copied to clipboard

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

Open grschafer opened this issue 2 years ago • 3 comments

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.

grschafer avatar Mar 10 '22 01:03 grschafer

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.

thebengeu avatar Mar 10 '22 04:03 thebengeu

Hi @grschafer, can this be solved by adding the download attribute to the anchor tag instead?

inian avatar Jul 29 '22 09:07 inian

Hey @inian, the download attribute wasn't a good solution when I last tried it -- see bullet points 1 and 2 under the "Describe alternatives you've considered" heading in my original issue post.

grschafer avatar Jul 29 '22 15:07 grschafer

Looking forward to this feature!

Heath101 avatar Sep 06 '22 20:09 Heath101

PR is up - this feature will land shortly! 🎉

fenos avatar Sep 29 '22 14:09 fenos