Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html Can';t创建二进制JPEG的Base64表示形式_Html_Vue.js - Fatal编程技术网

Html Can';t创建二进制JPEG的Base64表示形式

Html Can';t创建二进制JPEG的Base64表示形式,html,vue.js,Html,Vue.js,所以,这肯定是我无法忍受的。我允许用户存储图像,现在是私有的,因此我需要能够使用授权头请求图像其中所有x:s应替换为图像的Base64表示形式。我尝试使用btoa,但在我的Base64中只有大约20个字符。图像大小为700Kb 是不是btoa无法处理如此大小的图像 还有别的方法吗 我不使用browserify或webpack,所以我不想使用缓冲区来解决这个问题 编辑:我收到的第一条评论实际上是对我的问题的正确回答,只是做了一个小小的调整 getBase64(arrayBuffer) {

所以,这肯定是我无法忍受的。我允许用户存储图像,现在是私有的,因此我需要能够使用授权头请求图像<代码>其中所有x:s应替换为图像的Base64表示形式。我尝试使用
btoa
,但在我的Base64中只有大约20个字符。图像大小为700Kb

  • 是不是
    btoa
    无法处理如此大小的图像
  • 还有别的方法吗
我不使用browserify或webpack,所以我不想使用缓冲区来解决这个问题

编辑:我收到的第一条评论实际上是对我的问题的正确回答,只是做了一个小小的调整

  getBase64(arrayBuffer) {
    var reader = new FileReader();
    var that = this;
    reader.onloadend = function () {
      that.mainImage = reader.result;
    };

    reader.readAsDataURL(new Blob([new Uint8Array(arrayBuffer)], { type: 'image/jpeg' }));
  }
我添加了一个
Blob
来包含我的
ArrayBuffer
,我必须转换
ArrayBuffer
UInt8Array
,使blob能够在其上迭代

在我的Vue模板中

<img class="responsive-img" :src="mainImage"></img>

试试这个

getBase64(file) {
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function () {
          console.log(reader.result);
        };
      },

this.getBase64(this.selected_file);