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