概述通过解析 `Content-Disposition` 获取服务器建议文件名,并完成本地保存。解析与保存function parseFilename(cd) { if (!cd) return 'download'; const m = cd.match(/filename\*=UTF-8''([^;]+)|filename="?([^";]+)"?/i); return decodeURIComponent(m?.[1] || m?.[2] || 'download'); } async function saveResponse(url) { const res = await fetch(url); const name = parseFilename(res.headers.get('Content-Disposition')); const h = await window.showSaveFilePicker({ suggestedName: name }); const ws = await h.createWritable(); const ab = await res.arrayBuffer(); await ws.write(new Uint8Array(ab)); await ws.close(); }

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部
1.959954s