Skip to content

Instantly share code, notes, and snippets.

@p2yang p2yang/download.js

Last active Feb 12, 2020
What would you like to do?
原生 fetch download file
async function download (url = '', headers = {}) {
try {
const res = await fetch(url, {
const blob = await res.blob()
// 获取后端headers里面的文件名
const filename = decodeURI(res.headers.get('Content-Disposition').split('filename=')[1])
// download
const a = document.createElement('a') = filename = 'none'
a.href = window.URL.createObjectURL(blob)
} catch (err) {
// toast error message

This comment has been minimized.

Copy link
Owner Author

p2yang commented Feb 12, 2020

thanks for the issue comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.