关于需要登录才能访问的图片 怎么通过 API 接口返回
vue 后台管理 table 行里 需要 显示身份证敏感照片
图片不是存在public 目录里面 此情景下需要做什么样的处理能才比较好的显示图片
{
"user_id": "1",
"pics": [
"a.jpg",
"b.jpg",
"c.jpg",
"d.jpg"
]
}
是不是要用一个新的route 类似这样 http://www.***.*com/needAuth?pic=a.jpg
img(pic){
let t=this;
axios.get("http://www.***.*com/needAuth?pic="+pic, {
responseType: 'arraybuffer',
headers:{"validtoken":this.$store.getters.token}
}).then(response => {
return 'data:image/png;base64,' +btoa(new Uint8Array(response.data).reduce((data, byte) => data + String.fromCharCode(byte), ''));
}).then(data=>{
t.ImgData.push(
{url:data,
row:id
})
return data
});
},
烦请大神指点一下
header('Content-type:image/png');
echo file_get_contents(ROOT_PATH . $filepath);
获取接口是带着权限控制的就可以了。