SOURCE

/*
    文件 blob 类型转成 file 类型(异步任务) 
    blob        ==> blob 文件类型
    fileName    ==> 文件名称
    fileType    ==> 文件类型
*/
async function fnBlobToFile(blob, fileName, fileType) {
    return new window.File([blob], fileName, {
        type: fileType,
        lastModified: Date.now()
    })
}
/*
    下载文件File类型
    fileUrl ==> 文件url链接
    fileName==> 文件名称
*/
async function fnDownloadFile(fileUrl, fileName) {
    if (!fileUrl) return;
    let res = await axios({
        method: "get",
        url: fileUrl,
        responseType: "blob",
        onDownloadProgress: (progressEvent) => {
            if (progressEvent.lengthComputable) {
                console.log(`下载进度:${progressEvent.loaded / progressEvent.total * 100}`);
            }
        }
    });
    if (res.status !== 200) {
        console.log('获取文件失败~');
        return;
    }
    let {
        data
    } = res;
    fnBlobToFile(data, fileName, data.type).then(res => {
        console.log('File类型:', res);
    })
}

fnDownloadFile(
    'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb.zol-img.com.cn%2Fdesk%2Fbizhi%2Fimage%2F6%2F960x600%2F1426818724752.jpg&refer=http%3A%2F%2Fb.zol-img.com.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1627377638&t=662034e86ff9110854ca0316485e294b',
    'downFiles');
console 命令行工具 X clear

                    
>
console