1
0
Fork 0
mirror of synced 2024-07-03 13:30:46 +12:00
This commit is contained in:
Adria Navarro 2024-03-25 10:24:20 +01:00
parent 19caf3cddf
commit df05cf2345

View file

@ -46,23 +46,23 @@ export async function downloadFile(url, body) {
if (!response.ok) {
return false
} else {
const contentDisposition = response.headers.get("Content-Disposition")
const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(
contentDisposition
)
const filename = matches[1].replace(/['"]/g, "")
const url = URL.createObjectURL(await response.blob())
const link = document.createElement("a")
link.href = url
link.download = filename
link.click()
URL.revokeObjectURL(url)
return true
}
const contentDisposition = response.headers.get("Content-Disposition")
const matches = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/.exec(
contentDisposition
)
const filename = matches[1].replace(/['"]/g, "")
const url = URL.createObjectURL(await response.blob())
const link = document.createElement("a")
link.href = url
link.download = filename
link.click()
URL.revokeObjectURL(url)
return true
}