c# - 如何将数组 [] 转换为 HttpPostedFileBase
问题描述
我从数据库中获取信息,在这些信息之间有姓名、日期和图像,我想在表格中显示这些信息,并通过 ajax 以 json 格式发送信息。
这里执行查询并将信息带入数据库的方法,观察到的新列表是由于要保存已转换为 HttpPostedFileBase 的照片字段
public async Task<JsonResult> GetEmpleados(HttpPostedFileBase Foto)
{
List<spr_GetEmpleados> listaEmpleados = new List<spr_GetEmpleados>();
listaEmpleados.Clear();
using (var db = new AppDbContext())
{
listaEmpleados = await db.Set<spr_GetEmpleados>().SqlQuery("EXEC spr_GetEmpleados").ToListAsync();
var newlist = listaEmpleados.Select(x => new
{
idEmpleado=x.Id,
Nombres=x.Nombres,
Apellidos=x.Apellidos,
Correo=x.Correo,
FechaRegistro=x.FechaRegistro,
FechaNacimiento=x.FechaNacimiento,
Departamento = x.Departamento,
Foto=Imagen.ConvertImage(x.Foto)
});
db.Dispose();
var jsonResult = Json(new { success = true, data = newlist.ToList() }, "application/json",
System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet);
jsonResult.MaxJsonLength = int.MaxValue;
return jsonResult;
}
}
在这种方法中会发生转换,我将转换为 Image 类型只是为了测试,但想法是将其更改为 HttpPostedFileBase 类型
public static Image ConvertImage(byte[] Foto)
{
using (MemoryStream memoryStream = new MemoryStream(Foto))
{
var foto = Image.FromStream(memoryStream);
return foto;
}
}
解决方案
推荐阅读
- amazon-web-services - 将保留策略添加到发布到 CloudWatch 的 API Gateway 日志
- spring-cloud-stream - Spring Cloud 数据流 | 卡夫卡粘合剂 | 错误:KafkaTopicProvisioner - 无法创建主题
- angular - 如何使用带有 ionic4 和电容器的第三方 javascript 库?
- couchbase - cbrestore 5.1 可以恢复 cbbackup 6.0 的备份吗?
- excel - ListBox 不返回结果
- python - Django Rest框架中多对多中间模型的接近方式
- angular - 使用 immer.js - 重新分配草稿数组引用会导致状态中的相同数组引用
- python - 将两个字典相加,字母数字项除外
- sql - 在 prodecure 中按一个查询搜索
- kubernetes - 如果 Kubernetes 服务失败会发生什么?