简体   繁体   English

用 express 在前端读取 Base64 图像

[英]Reading a Base64 image in front-end with express

I'm setting up a project, and I decided that the best alternative was to save the images in Base64 and save it in the database.我正在建立一个项目,我决定最好的选择是将图像保存在 Base64 中并将其保存在数据库中。 This is OK, all right.这没关系,好​​吧。 However, when I need to render them on the front end, the following is not working, for some reason, can someone help me?但是,当我需要在前端渲染它们时,以下不起作用,出于某种原因,有人可以帮助我吗?

<img class="whatever" src="<%= datasetresult[1].photo%>">

When I look at the browser console, Base64 is there, so I don't understand why it isn't rendering.当我查看浏览器控制台时,Base64 就在那里,所以我不明白为什么它没有呈现。

HELP!帮助!

EDIT编辑

那是 Chrome 的控制台

The src tag of images can accept base64 strings, if you specify the type.如果指定类型,图像的src标签可以接受 base64 字符串。 For example, if you have a jpeg image, you need to prefix the base64 string with data:image/jpeg;base64, .例如,如果您有 jpeg 图像,则需要在 base64 字符串前加上data:image/jpeg;base64,

If you have SVG (with or without raster data), you need to use data:image/svg+xml;base64, .如果你有 SVG(有或没有光栅数据),你需要使用data:image/svg+xml;base64, .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM