我有这个图像标签,它必须位于我无法使用 Javascript 的电子邮件中。鉴于 API 正在运行且由我自己编写,如何使此图像标签 src 从我的 API 获取 Base64 数据?
<img src="https://qr-generator-test.herokuapp.com/create-qr-code?data=184B2598-E19C-
4454-95CE-6BD7498F21D4" style="max-width:300px; width: 100%; padding: 0px;
text-align: center; display:block;" width="300">
或者我可以编辑我的 API 来做一些更聪明的事情吗?有什么解决办法吗?
最佳答案
在向客户发送电子邮件之前,请将 src attr 更改为有效的 Base64 图像:
<img src="data:image/gif;base64,..." style="max-width:300px; width: 100%; padding: 0px;
text-align: center; display:block;" width="300">
这里您必须将二维码图像二进制编码为base64。
或者将其设置为您当前的网址并按常规显示图像。
<img src="https://qr-generator-test.herokuapp.com/create-qr-code?data=184B2598-E19C-
4454-95CE-6BD7498F21D4" style="max-width:300px; width: 100%; padding: 0px;
text-align: center; display:block;" width="300">
为此,您需要返回 url 上的图像二进制数据,仅此而已。 没有指向其他图像的 URL,没有文本,只有 QR 码中的纯二进制文件。
当我访问:https://qr-generator-test.herokuapp.com/create-qr-code?data=184B2598-E19C-%204454-95CE-6BD7498F21D4
时,我得到一个URL ,不是有效图像。 https://qr-generator-test.herokuapp.com/qr-code/55m1bnju1367f7.png
指向二维码图像。
我希望我能澄清您的问题所在。
关于javascript - 我可以使 src 属性从服务器或调整服务器获取 base64 数据吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55478310/