Asp.net mvc save and display images in db

how are you going to save images and display them from the SQL Server image field when using ASP.NET MVC?

Thanks a lot Nick

+3
source share
2 answers

The MvcFutures project http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=18459 has a FileResult, which is an ActionResult type. You can probably use this to return the binary stream to the browser.

+2
source

You can also do this quite simply with a controller action:

public void RenderImage(int imageId)
{
    // TODO: Replace this with your API to get the image blob data.
    byte[] data = this.repo.GetImageData(imageId);

    if (data != null)
    {
        // This assumes you're storing JPEG data
        Response.ContentType = "image/jpeg";
        Response.Expires = 0;
        Response.Buffer = true;
        Response.Clear();
        Response.BinaryWrite(data);
    }
    else
    {
        this.ControllerContext.HttpContext.ApplicationInstance.CompleteRequest();
    }
}
0
source

Source: https://habr.com/ru/post/1699162/


All Articles