FileStreamResult displays empty browser document when rendering image from stream in MVC3

↘锁芯ラ 提交于 2019-12-04 21:08:26

You don't need a stream if you already have a byte array of the photo:

public ActionResult Photo(int id)
{
    var data = db.Photos.FirstOrDefault(p => p.PhotoID == id);
    if (data == null)
    {
        return HttpNotFound();
    }
    return File(data.PhotoData, "image/jpeg");
}

The problem with your code is that you need to reset the memory stream at the beginning but as I said you don't need all this.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!