Through a web api I am getting the path of an image stored on the server. The path is a string that I convert to an array of bytes and then convert it to a base64 image. When I visualize the image in the view, it does not throw an error but it does not load any image. I can not find where I have the error.
CODE:
// Por cada registro que obtengo, transformo el campo "adjunto" (ruta de la imagen) en arreglo de bytes
private MisTurnos MapearAMisTurnosDesdeRegistro(Registro registro)
{
return new MisTurnos
{
Codigo = Convert.ToInt32(registro["numero"]),
Fecha = Convert.ToDateTime(registro["fecha"]),
Hora = registro["hora"].ToString(),
Servicio = registro["servicio"].ToString(),
Sucursal = registro["sucursal"].ToString(),
Estado = Convert.ToInt32(registro["estado"]),
// Esta propiedad es la que utilizo para guardar la imagen
Orden = Encoding.UTF8.GetBytes(registro["adjunto"].ToString())
};
}
// Por cada registro que obtuve del web api con la ruta de la imagen correspondiente
// transformada en arregl ode bytes, transformo ese arreglo en base64
private IEnumerable<MisTurnosViewModel> ConvertirOrdenEnImagen(IEnumerable<MisTurnosViewModel> listaTurnos)
{
foreach (var item in listaTurnos)
{
item.OrdenImagen = "data:image/png;base64," + Convert.ToBase64String(item.Orden);
}
return listaTurnos;
}
Finally, in the view, I show in a tag the property OrderImage, which contains the image transformed to base64:
<img [email protected] />