node.js 用axios下载图片转换为Base64
作者:
茅坑里的小石头 | 来源:发表于
2020-04-07 12:55 被阅读0次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
本文链接:https://www.haomeiwen.com/subject/psggphtx.html
网友评论