javascript - 如何将从json获取的字节数组更改为图像
问题描述
我将图像和数据存储在数据库中,我有.net Core API,它发回包含一些数据和图像数组的对象。如何以角度在页面上显示该图像?我尝试使用FileReader
和它的功能readAsDataURL
,但我不能让它工作和/或不能将图像转换为 blob。
从 API 发回的对象模型:
public class ControlPoint
{
public int Id { get; set; }
public string Location { get; set; }
public string Confirmation { get; set; }
public ICollection<Image> Images { get; set; }
public ControlPointType Type { get; set; }
}
图像模型:
public class Image
{
public int Id { get; set; }
public Guid ROWGUID { get; set; }
public string FileName { get; set; }
public DateTime DateAdded { get; set; }
public int ControlPointId { get; set; }
public byte[] Stream { get; set; }
}
角度控制点模型:
export interface ControlPoint {
id: number;
location: string;
confirmation: string;
images: Photo[];
type: ControlPointType;
}
角度图像模型:
export class Photo {
fileName: string;
dateAdded: Date;
controlPointId: number;
stream: any;
}
我该如何处理?我认为我无法将响应类型更改为 blob,因为我在 json 中获取了整个对象,而不仅仅是图像。
解决方案
推荐阅读
- vue.js - vue 在没有 v-model 等的情况下一次更新表单输入值
- node.js - Azure Web 应用程序:无法运行任何需要依赖项的 npm/yarn 脚本(找不到命令)
- python - 根据阈值删除行
- .htaccess - 使用 htaccess 从 URL 中删除类别
- autodesk-forge - 尝试获取项目的顶级文件夹时“区域设置无法返回区域”
- angular - Webpack 忽略 node-pre-gyp 文件
- c++ - 没有运算符“<<”匹配这些操作数递归河内塔错误
- css - 为什么在我的主 Web 容器上将宽度设置为 100% 会在移动设备上创建水平滚动条?
- javascript - 将 nuxt 2.12 升级到 2.15.8 错误“未找到此依赖项”?
- javascript - 笑话错误:找不到给定节点的“窗口”对象