首页 > 解决方案 > HTML SVG - load base64 string data to href of or any workaround

问题描述

I am trying to create an SVG orgchart and the get api returns json with each item (employee) having a property that is a base64 string representing an image

I want to load the base64 similar to non-svg <img> element with src="data:image/png;base64," but it doesn't seem to work with the svg element <image>

I also tried using <foreignObject> then appending <img> inside but it also does not work for base64, it only works when you have a url of the image.

I verified that the base64 string is good since when you right click the src and opened it in new tab, it actually loads the image in the new tab.

标签: javascripthtmlsvg

解决方案


对于可能的错误信息,我们深表歉意。异物内的 img 标签确实允许使用 data:image 格式的 base64 图像,但被我网站上的内容安全策略阻止。


推荐阅读