前端上传图片,传到后端,然后后端直接把图片以image形式存入数据库,待前端请求时,再从数据库中取出,传给前端,逻辑上好像没什么问题,但是在实际操作过程中,前端获取到数据后并不能直接使用<img src=res.data/>
来显示图片
responseType:"arraybuffer"
axios.get(‘http://xxxx.xxxx.xxx‘,{responseType:"arraybuffer"})
xhr.responseType = ‘arraybuffer‘
const blob = new Blob([responseData], { type: imageType })
const imageUrl = (window.URL || window.webkitURL).createObjectURL(blob)
<img src={imageUrl}>
JavaScript如何转换二进制数据显示成图片
Axios中文说明
原文:https://www.cnblogs.com/selfdef/p/12907642.html