baseddata.io/layouts/shortcodes/download-data.html

22 lines
585 B
HTML
Raw Permalink Normal View History

2024-08-13 18:52:51 +01:00
<button class="download-button" onclick="downloadFile('{{ .Get "src" }}', '{{ .Get "name" }}')">
Download
</button>
<script>
async function downloadFile(url, name) {
try {
const response = await fetch(url);
const blob = await response.blob();
const link = document.createElement('a');
link.href = URL.createObjectURL(blob);
link.download = name;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} catch (error) {
console.error('Error downloading the file:', error);
}
}
</script>