如何将图像数据响应转换为 Image base64?

san*_*eni 5 javascript reactjs axios

这是我的 api

https://besticon-demo.herokuapp.com/icon?url=facebook.com&size=80..120..200

当我在邮递员中测试这个时,我得到了 Image..但是我怎么能用axios. 我现在用 Axios 得到了很长的字符串(比如?PNG...)

那么我如何使用该响应来显示图像..

   axios.get(RequestURL, { withCredentials: false })
                .then(function (response) {
                    // handle success
                    console.log(response)
                    var b64Response = btoa(response.data) 
                    setImageServer('data:image/png;base64,' + b64Response) // not showing image
                })
Run Code Online (Sandbox Code Playgroud)

尝试运行时也会出错 btoa

DOMException:无法在“Window”上执行“btoa”:要编码的字符串包含超出 Latin1 范围的字符。

HTML

 <img src={ImageServer}/>
Run Code Online (Sandbox Code Playgroud)

Kin*_*one 4

axios.get('RequestURL', { responseType: 'arraybuffer' })
.then(response => {
      let blob = new Blob(
        [response.data], 
        { type: response.headers['content-type'] }
      )
      let image = window.URL.createObjectURL(blob)
      return image
    })
Run Code Online (Sandbox Code Playgroud)
axios.get('RequestURL', {responseType: 'blob'})
.then(response => {
  let imageNode = document.getElementById('image');
  let imgUrl = URL.createObjectURL(response.data)
  imageNode.src = imgUrl
})
Run Code Online (Sandbox Code Playgroud)