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.

option to download files rather than view

See original GitHub issue

serve-index is great because it allows a quick, generic file viewer.

I’ve been using it for https://telebit.cloud’s directory serving option (telebit http ~/path/to/share) as a poor-man’s airdrop/dropbox so that I quickly share files with others.

However, there are two things that make it somewhat inconvenient:

  • inability to quickly download a file
  • inability to quickly download a group of files

If we had a download icon next to the file that would append ?download=true to the url, then that could be a cue to serve-static to add the appropriate Content-Disposition header so that an image would download rather than go into view mode.

Likewise, if we had the option to save as zip that would append ?download=true&format=zip we could have serve-index provide the file as a zip file (and leave the dependency as optional, simply returning an error if the option in enabled and the dependency is not installed).

I’m wondering if you’d be open to either or both of these suggestions.

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:16 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
AverTrycommented, Mar 15, 2021

I would like to propose a simple feature-request for the specific issue: Why not add a new option {downloadAttr: true} which would create links with the download attribute?

As a workaround for now, you can copy use the existing directory.html template ( {template: './directory.html'} ) adding the following at the end of body tag:

<script>document.querySelectorAll("#files a").forEach((el)=>el.setAttribute("download", ""));</script>

Needed this, but it tries to download directories too, my work around is

<script> document.querySelectorAll("#files a").forEach( (el) => { if(!el.classList.contains('icon-directory')) { el.setAttribute("download", "") } }) </script>

0reactions
ghusercommented, Oct 21, 2019

I would like to propose a simple feature-request for the specific issue: Why not add a new option {downloadAttr: true} which would create links with the download attribute?

As a workaround for now, you can copy use the existing directory.html template ( {template: './directory.html'} ) adding the following at the end of body tag:

<script>document.querySelectorAll("#files a").forEach((el)=>el.setAttribute("download", ""));</script>

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Download PDF instead of Viewing in Chrome?
Select the PDF Documents menu. Enable the toggle button for Download PDF files instead of automatically opening them in Chrome.
Read more >
Download a file - Computer - Google Chrome Help
See a list of files you've downloaded. On your computer, open Chrome. At the top right, click More More and then Downloads. To...
Read more >
My file automatically opens instead of saving when I download ...
Scroll down to Advanced Settings, click Downloads, and clear your Auto Open options. Next time you download an item, it will be saved...
Read more >
How to Change Browser Download Settings for PDF Files
This page shows how to make the browser download PDF files instead of opening them automatically and vice versa. Select your browser from ......
Read more >
Make Google Chrome Download PDF Files Instead of Opening
Make Google Chrome Download PDF Files Instead of Opening ... When you are clicking on a link to a PDF file in Google...
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