Skip to content

Commit

Permalink
Add downloadUrl snippet
Browse files Browse the repository at this point in the history
  • Loading branch information
gissehel authored and gissehel committed Dec 24, 2024
1 parent e97b5bf commit fb89479
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions snippet/downloadUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
*
* @param {String} url The url to download
* @param {String} filename The filename to use to save the file
* @returns
*/
const downloadUrl = async (url, filename) => {
const response = await fetch(url);
const blob = await response.blob();
const urlContent = window.URL.createObjectURL(blob);
const a = createElementExtended('a', {
attributes: {
href: urlContent,
target: '_blank',
download: filename,
},
})
a.click()
}

0 comments on commit fb89479

Please sign in to comment.