fix click textarea.
This commit is contained in:
23
src/utils/download.ts
Normal file
23
src/utils/download.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import axios from "axios"
|
||||
|
||||
const http = axios.create({
|
||||
baseURL: "/api/admin",
|
||||
responseType: "blob",
|
||||
xsrfHeaderName: "X-CSRFToken",
|
||||
xsrfCookieName: "csrftoken",
|
||||
})
|
||||
|
||||
async function download(url: string) {
|
||||
const res = await http.get(url)
|
||||
const headers = res.headers
|
||||
const link = document.createElement("a")
|
||||
link.href = window.URL.createObjectURL(
|
||||
new window.Blob([res.data], { type: headers["content-type"] })
|
||||
)
|
||||
link.download = (headers["content-disposition"] || "").split("filename=")[1]
|
||||
document.body.appendChild(link)
|
||||
link.click()
|
||||
link.remove()
|
||||
}
|
||||
|
||||
export default download
|
||||
Reference in New Issue
Block a user