let base64Str = "data:image/jpeg;base64,"+base64; let aLink = document.createElement("a"); aLink.style.display = "none"; aLink.href = base64Str; aLink.download = "test.jpg"; // 触发点击-然后移除 document.body.appendChild(aLink); aLink.click(); document.body.removeChild(aLink); ?
let ab = Buffer.from(res.data.content, "binary");
const base64 = "data:image/png;base64," + ab.toString('base64');
const blob = new Blob([ab], {
type: 'image/jpeg'
});
const filename = 'img' + new Date().getTime();
if (window.navigator.msSaveOrOpenBlob) {
navigator.msSaveBlob(blob, filename);
} else {
const link = document.createElement("a");
const body = document.querySelector("body");
link.href = window.URL.createObjectURL(blob); // 创建对象url
link.download = filename;
// fix Firefox
link.style.display = "none";
body.appendChild(link);
link.click();
body.removeChild(link);
window.URL.revokeObjectURL(link.href); // 通过调用 URL.createObjectURL() 创建的 URL 对象
}
|