一.通过fs模块
const fs = require('fs');
const filePath = '';
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) {
console.error(err);
return;
}
// 处理读取到的文件数据
console.log(data);
})
二.通过获取流 返回一次性链接
url="http://xxxx/test.png";
dir="D:/files"
let topPictureUrl = url.substr(url.lastIndexOf("/") + 1);
let p_uint8Buffer = Uint8Array.from(
fs.readFileSync(dir + "/" + topPictureUrl)
);
let bolb = new Blob([p_uint8Buffer]);
this.allFileData.topPictureUrl = URL.createObjectURL(bolb);
三.绝对路径(打包后)
<img src="/12309Files/240117109337972310016/856d87a072171c488aae17f41455c4c.png" alt="">