修复下载文件被追加 .bin 扩展名:blob 置空 MIME,避免移动端浏览器按 octet-stream 类型补 .bin

This commit is contained in:
2026-08-31 19:43:52 +08:00
parent 1becf740c3
commit 6d3c965cf7
+4 -3
View File
@@ -369,15 +369,16 @@ async function downloadFile(name) {
const url = '/api/sessions/' + state.sessionId + '/files/download?path=' + encodeURIComponent(name);
const res = await fetch(url);
if (!res.ok) throw new Error('HTTP ' + res.status);
const blob = await res.blob();
let blob = await res.blob();
// 抹掉 blob 的 MIME:响应常为 octet-stream,部分移动端浏览器内核会按类型给下载名追加 .bin,抹掉后按原名保存
try { blob = new Blob([blob], { type: '' }); } catch (_) {}
const dlUrl = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = dlUrl;
a.download = name.split('/').pop() || 'download';
document.body.appendChild(a);
a.click();
a.remove();
setTimeout(function () { URL.revokeObjectURL(dlUrl); }, 1000);
setTimeout(function () { a.remove(); URL.revokeObjectURL(dlUrl); }, 1000);
} catch (e) {
toast('下载失败:' + e.message);
}