9***@qq.com
9***@qq.com
  • 发布:2018-02-10 17:09
  • 更新:2018-02-10 17:15
  • 阅读:2023

mui无法上传base64字符串

分类:MUI
mui

如果直接把base64字符串赋值给变量就可以上传,但是从系统获取的base64无法上传,从系统获取的base64是可以打印到控制台的没问题。我现在毫无头绪,毫无理由的错误。

2018-02-10 17:09 负责人:无 分享
已邀请:
9***@qq.com

9***@qq.com (作者) - 蕾姆爷爷

上面的代码显示不出来。改成上传txt文本压缩的。大神给我看一看吧

3***@qq.com

3***@qq.com - 好喜欢hbuilder

我用函数压缩得到base64, 好像没什么问题

//将图片压缩转成base64
function getBase64Image(img) {
var canvas = document.createElement("canvas");
var width = img.width;
var height = img.height;
//calculate the width and height, constraining the proportions
if (width > height) {
if (width > 50) {
height = Math.round(height = 50 / width);
width = 50;
}
} else {
if (height > 50) {
width = Math.round(width
= 50 / height);
height = 50;
}
}
canvas.width = width; /设置新的图片的宽度/
canvas.height = height; /设置新的图片的长度/
var ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0, width, height); /绘图/
var dataURL = canvas.toDataURL("image/png", 0.8);
return dataURL.replace("data:image/png;base64,", "");
}

该问题目前已经被锁定, 无法添加新回复