[英]Conversion of base64 to image results in a “Failed to load resource: net::ERR_INVALID_URL” error when array is used.
Basically when I use: 基本上,当我使用:
imageObj.src = "data:image/webp;base64,data[2]";
It will give me an error. 这会给我一个错误。
However, when I console.log(data[2]) and then copy and paste whatever data[2] is into the code like this: 但是,当我console.log(data [2])然后将任何data [2]复制并粘贴到这样的代码中时:
imageObj.src = "data:image/webp;base64,sampleexampleasfnakdjfbaksjbrwkaerhdhcoaunsf";
Everything works out. 一切顺利。 Please help me understand? 请帮我理解吗?
Javascript does not interpolate variables inside strings like some languages. JavaScript不会像某些语言一样在字符串内插变量。 If data[2] is a string, use string concatenation to add data[2] to the URI: 如果data [2]是字符串,请使用字符串串联将data [2]添加到URI:
imageObj.src = "data:image/webp;base64,"+data[2];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.