图片文件转二进制并返回前台显示

后台:

pub­lic Action­Re­sult GetUserPic(Guid id)
{
Car­dAc­ces­so­ryEn­ti­ty car­dAc­ces­sories = new CardAccessoryService().GetCardAccessories(id);//根据id获取文件路径
string path =cardAccessories.url //图片路径;
if (System.IO.File.Exists(path)) //判断文件是否存在
{
// 读文件成二进制流
using (FileStream stream = new FileStream(path, FileMode.Open))
{
long buffer­Length = stream.Length;
byte[] buffer­File = new byte[bufferLength];
stream.Read(bufferFile, 0, bufferFile.Length);
string con­tent­Type = “image/jpeg”;
stream.Close();
return new FileContentResult(bufferFile, con­tent­Type);
}
}
}

为您推荐

发表评论

您的电子邮箱地址不会被公开。