使用axios发布请求下载图像

时间:2019-11-22 17:55:38

标签: javascript highcharts axios

我需要'http://export.highcharts.com/'

的base64图像图表
    getImg () {
          const self = this;
          axios.post('http://export.highcharts.com/', { options: self.$refs['lineChart'].options, type: 'image/png' }).then(function (response) {
            base64.encode(response.data)
          }).catch(function (e) {
            console.log(e)
          });
    },

2 个答案:

答案 0 :(得分:0)

在这里您可以获取图像并将其转换为base64。也与此问题类似,您可以查看以下link以获得更多信息。

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

答案 1 :(得分:0)

这很好

getImg () {
          const self = this;
          axios.post('http://export.highcharts.com/', { options: self.$refs['lineChart'].options, type: 'image/png' }, { responseType: 'arraybuffer' }).then(function (response) {
            let PNGBase64 = 'data:image/png;base64,' + Buffer.from(response.data, 'binary').toString('base64')
          }).catch(function (e) {
            console.log(e)
          });
    },