3

how do you go about saving images and displaying them from a SQL Server Image field when using ASP.NET MVC?

Many thanks Nick

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

You can also do this pretty simply yourself 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();
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.