简体   繁体   English

使用数组时,将base64转换为图像会导致“无法加载资源:net :: ERR_INVALID_URL”错误。

[英]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.

相关问题 获取数据:image / png; base64,{{image}} net :: ERR_INVALID_URL - GET data:image/png;base64,{{image}} net::ERR_INVALID_URL UI-grid net :: ERR_INVALID_URL,同时基于COL_FIELD有条件地显示base64图像 - UI-grid net::ERR_INVALID_URL while displaying base64 image conditionally based on COL_FIELD ReactJS,渲染base64字符串 <img> 标记给出错误ERR_INVALID_URL - ReactJS, rendering base64 string in <img> tag gives error ERR_INVALID_URL ERR_INVALID_URL - ERR_INVALID_URL NgImgCrop net :: ERR_INVALID_URL但有效的URI - NgImgCrop net::ERR_INVALID_URL but valid URI 由于 ERR_INVALID_URL 错误,传单 JS 中的标记无法正确加载 - Marker in leaflet JS does not load properly due to ERR_INVALID_URL error 加载资源失败:服务器响应状态为 500(内部服务器错误),同时从控制器返回 base64 格式的图像 - Failed to load resource: the server responded with a status of 500 (Internal Server Error) while returning image in base64 format from controller 图像到base64的转换 - image to base64 conversion 将图像转换为Base64时出错 - Error when converting Image to Base64 发出GET请求时出错“无法加载资源:net :: ERR_CONNECTION_REFUSED” - error when making GET request “Failed to load resource: net::ERR_CONNECTION_REFUSED”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM