后台:
public ActionResult GetUserPic(Guid id)
{
CardAccessoryEntity cardAccessories = new CardAccessoryService().GetCardAccessories(id);//根据id获取文件路径
string path =cardAccessories.url //图片路径;
if (System.IO.File.Exists(path)) //判断文件是否存在
{
// 读文件成二进制流
using (FileStream stream = new FileStream(path, FileMode.Open))
{
long bufferLength = stream.Length;
byte[] bufferFile = new byte[bufferLength];
stream.Read(bufferFile, 0, bufferFile.Length);
string contentType = “image/jpeg”;
stream.Close();
return new FileContentResult(bufferFile, contentType);
}
}
}