node.js 用axios下载图片转换为Base64

const axios = require('axios')
let url = 'https://cbu01.alicdn.com/img/ibank/2019/043/806/11230608340_1371494418.120x120.jpg';
function getBase64 (url) {
  return axios
    .get(url, {
      responseType: 'arraybuffer'
    })
    .then(response => new Buffer.from(response.data, 'binary').toString('base64'))
}
getBase64(url)
  .then(ret => {
    console.log(`data:image/jpg;base64,${ret}`)
  })

你可能感兴趣的:(node.js 用axios下载图片转换为Base64)