前端显示二进制流图片
最近调了一个第三方的接口,后台直接返回的是一个二进制流的图片,前端需要将它显示,写个博文记录一下,以下是它的代码:axios.get('https://ue1-260-mmg.demo.lunit.io/mmg/predictions', {responseType: 'arraybuffer',}).then(response => {return 'data:image/png;base
·
最近调了一个第三方的接口,后台直接返回的是一个二进制流的图片,前端需要将它显示,写个博文记录一下,以下是它的代码:
axios.get('https://ue1-260-mmg.demo.lunit.io/mmg/predictions', {
responseType: 'arraybuffer',
}).then(response => {
return 'data:image/png;base64,' + btoa(
new Uint8Array(response.data).reduce((data, byte) => data + String.fromCharCode(byte), '')
)
}).then(data => {
$('#bgImg').css('background-image', "url(" + data + ")")
})
更多推荐
所有评论(0)