mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
added download
util
This commit is contained in:
parent
64aed20214
commit
92964758d1
32
packages/app/src/utils/download/index.js
Normal file
32
packages/app/src/utils/download/index.js
Normal file
@ -0,0 +1,32 @@
|
||||
export default (uri, filename) => {
|
||||
fetch(uri, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/pdf",
|
||||
},
|
||||
})
|
||||
.then((response) => response.blob())
|
||||
.then((blob) => {
|
||||
if (!filename) {
|
||||
filename = uri.split("/").pop()
|
||||
}
|
||||
|
||||
// Create blob link to download
|
||||
const url = window.URL.createObjectURL(new Blob([blob]))
|
||||
|
||||
const link = document.createElement("a")
|
||||
|
||||
link.href = url
|
||||
|
||||
link.setAttribute("download", filename)
|
||||
|
||||
// Append to html link element page
|
||||
document.body.appendChild(link)
|
||||
|
||||
// Start download
|
||||
link.click()
|
||||
|
||||
// Clean up and remove the link
|
||||
link.parentNode.removeChild(link)
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user