c# - 如何将 URL从 Webapi 传递到标签以接受 base64 的图像?
问题描述
如何将 URL 传递Webapi
到<img>
标签中。我已将图像base64 string
转换Database
为varbinary
.
<img src="https://localhost:44381/api/Account/get-resource-image;data:image/jpg;base64" alt="img"/>
解决方案
您需要data:image/png;base64
在 src 中的 Webapi 端点的开头<img>
而不是之后添加。请参阅下面的代码。
<img src="data:image/jpg;base64,https://localhost:44381/api/Account/get-resource-imagedata" alt="img"/>
实现相同目的的另一种方法:
查询:
$.ajax({
url: 'https://localhost:44381/api/Account/get-resource-imagedata',
type: "GET",
success: function (data) {
$('#imgImage').attr('src', data);
}
});
在 HTML 中:
<img id="imgImage" src="#" alt="img"/>
推荐阅读
- python - 从数据框中提取多列并为不存在的列返回 NaN
- python - 如何计算列表中包含特定字母的单词数量?
- angular - dc.js 显示过滤后的对象计数
- asp.net - 导航属性是否必须在 EF Core 中显式设置?
- spring-boot - 异常时 RabbitMQ 消息未发送到死信队列
- android - 如何在 Kotlin 的 Fragment 中使用 Android AlarmManager?
- python - Django 如何记录客户端 IP 地址?
- ruby-on-rails - Rails Fog 基于远程链接创建文件
- apache-nifi - NIFI || 仅为 True 布尔表达式发送邮件
- frama-c - 如何在 ACSL 中编写“是 2 的幂”谓词?