option to download files rather than view
See original GitHub issueserve-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:
- Created 5 years ago
- Comments:16 (10 by maintainers)
Top GitHub Comments
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>
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>