Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: force downloading file when providing filename #195

Merged
merged 1 commit into from
Sep 30, 2022

Conversation

fenos
Copy link
Contributor

@fenos fenos commented Sep 26, 2022

What kind of change does this PR introduce?

feature

What is the current behavior?

we can only rely on HTML tags to download a file

What is the new behavior?

Adds a new query string parameter filename which if provided the file will be forced to be downloaded by the browser
by adding the content-disposition header

Additional context

Closes #122

@fenos fenos requested a review from inian September 26, 2022 13:50
@coveralls
Copy link

coveralls commented Sep 26, 2022

Pull Request Test Coverage Report for Build 3128286165

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 52 of 60 (86.67%) changed or added relevant lines in 3 files are covered.
  • 9 unchanged lines in 3 files lost coverage.
  • Overall coverage increased (+0.05%) to 86.22%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/routes/object/getObject.ts 21 24 87.5%
src/routes/object/getPublicObject.ts 19 24 79.17%
Files with Coverage Reduction New Missed Lines %
src/routes/object/getObject.ts 2 89.29%
src/routes/object/getSignedObject.ts 2 94.83%
src/routes/object/getPublicObject.ts 5 82.96%
Totals Coverage Status
Change from base Build 2976935757: 0.05%
Covered Lines: 2873
Relevant Lines: 3287

💛 - Coveralls

src/routes/object/getObject.ts Outdated Show resolved Hide resolved
@fenos fenos merged commit dbc75b1 into master Sep 30, 2022
@fenos fenos deleted the feat/download-file branch September 30, 2022 08:11
@github-actions
Copy link

🎉 This PR is included in version 0.21.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@JimH44
Copy link

JimH44 commented May 2, 2024

Thanks, developers, for this wonderful site. I'm wondering if the feature described here has broken recently?
I tried this query string in my browser:
https://github.com/silnrsi/unicode-resources/tree/main/ucd-spreadsheet/ucd.xlsx?filename=ucd.xlsx
to download the file "ucd.xlsx" from https://github.com/silnrsi/unicode-resources/tree/main/ucd-spreadsheet
but I got the message:
(Sorry about that, but we can’t show files that are this big right now.)
When I try
https://github.com/silnrsi/unicode-resources/tree/main/ucd-spreadsheet?filename=ucd.xlsx
I see the files in that folder. If I click on ucd.xlsx I see the message about showing files.
I can right-click the file and Save As, but I have a script that notices when this file is updated, and I would like it to be able to download the updated file itself, and not just ask me to download it :-)
Thanks for thinking about this, Jim

@JimH44
Copy link

JimH44 commented May 2, 2024

Or perhaps I didn't understand how to use the query string parameter "filename" properly.

@JimH44
Copy link

JimH44 commented May 11, 2024

@inian and @fenos , I like the look of what you did to let us create a link that would download a file from github rather than showing it. I'm wondering if that feature has broken recently. Would you have time to look at my comment to this issue, at #195 (comment)
Thanks for thinking about this, Jim

@khera
Copy link

khera commented Oct 27, 2024

Or perhaps I didn't understand how to use the query string parameter "filename" properly.

Anyone coming here in the future: the correct parameter to add is download=FILENAME where FILENAME can be blank or a name you want it to download. It is not called filename now.

@JimH44
Copy link

JimH44 commented Oct 28, 2024

Thanks @khera , I added ?download=ucd.csv to the link in the README file for this project, but still got the message
[View raw](https://github.com/silnrsi/unicode-resources/raw/refs/heads/main/ucd-spreadsheet/ucd.csv) (Sorry about that, but we can’t show files that are this big right now.)
The URL that I tried is
https://github.com/silnrsi/unicode-resources/blob/main/ucd-spreadsheet/ucd.csv?download=ucd.csv
What should I have used to get the file to download without any attempt at previewing it?
(I'm using Chrome on macos.)
@inian and @fenos , would you have time to look at this also, and show me the link to suggest in the README file, to download the file instead of trying to preview it?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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