1.浏览器默认可以预览视频、图片、pdf等文件。
2.如果浏览器预览不了的文件,拿到对应的文件流并打开网页会直接弹出文件夹并下载。
export const previewDownfile = (uuid, type, filename,name,item) => {
console.log("item",item)
if (uuid) {
download(uuid).then((res) => {
if (type == 'down') {
let blob = new Blob([res], {
type: 'application/octet-stream',
'Content-Disposition': 'attachment'
});
const link = document.createElement("a");
let objectUrl = window.URL.createObjectURL(blob);
link.style.display = "none";
link.href = objectUrl;
link.download = filename;
document.body.appendChild(link);
link.click();
URL.revokeObjectURL(link.href);
document.body.removeChild(link);
} else {
let blob = new Blob([res], {
type: `${name};charset-UTF-8`
});
window.open(window.URL.createObjectURL(blob))
}
});
}
}