26 lines
784 B
HTML
26 lines
784 B
HTML
<button class="download-button" onclick="downloadFile('{{ .Get "src" }}', '{{ .Get "name" }}')">
|
|
Download
|
|
</button>
|
|
|
|
<script>
|
|
async function downloadFile(url, name) {
|
|
try {
|
|
const response = await fetch(`${"{{ .Site.Params.apiURL }}"}/download${url}`);
|
|
if (!response.ok) {
|
|
throw new Error('Network response was not ok');
|
|
}
|
|
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);
|
|
URL.revokeObjectURL(link.href); // Clean up the object URL
|
|
} catch (error) {
|
|
console.error('Error downloading the file:', error);
|
|
}
|
|
}
|
|
</script>
|
|
|