<script lang="ts">
async function downloadFile(url: string, name: string) {
const fileFetch = await fetch(url);
const fileBlob = await fileFetch.blob();
const a = document.createElement('a');
const blobUrl = URL.createObjectURL(fileBlob);
a.href = blobUrl;
a.download = name;
a.click();
URL.revokeObjectURL(a.href);
}
</script>
<button
onclick={() => {
downloadFile('https://constt.de/gallery/constt-white.png', 'constt-white.png');
}}>Download</button
>
Download File from URL
How to download a file from a URL
Tags:
svelte
typescript
download
file