blob文件下载

js文件下载,接口返回的是blod
/**
 * blob文件下载
 * @param {} blob 流文件
 * @returns
 */
function downloadBlobFile(blob, filename) {
    if (!blob) return
    const url = window.URL.createObjectURL(
        new Blob([blob], {})
    )
    triggerDownload(url, filename)
}
function triggerDownload(url, filename) {
    // 创建隐藏的可下载链接
    const link = document.createElement('a')
    link.style.display = 'none'
    link.href = url
    if (filename) {
        link.setAttribute('download', filename)
    }
    document.body.appendChild(link)
    link.click()
    document.body.removeChild(link)
}

 

posted @ 2025-01-14 14:02  hong_li  阅读(22)  评论(0)    收藏  举报