【问题标题】:Download an image using axios post request使用 axios post 请求下载图像
【发布时间】:2019-11-23 03:34:52
【问题描述】:

我需要来自'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)
          });
    },

【问题讨论】:

标签: javascript highcharts axios


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    这很好用

    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)
              });
        },
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-12
      • 2016-10-11
      • 2012-10-19
      • 1970-01-01
      • 2018-06-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多