Download an image using Axios and convert it to base64

后端 未结 3 856
忘了有多久
忘了有多久 2020-11-29 02:11

I need to download a .jpg image from a remote server and convert it into a base64 format. I\'m using axios as my HTTP client. I\'ve tried issuing a git request to the server

3条回答
  •  被撕碎了的回忆
    2020-11-29 02:56

    This worked great for me:

    function getBase64(url) {
      return axios
        .get(url, {
          responseType: 'arraybuffer'
        })
        .then(response => Buffer.from(response.data, 'binary').toString('base64'))
    }
    

提交回复
热议问题