tags:

views:

15

answers:

1

i want to create an image handler that will resize and serve images to my application, how do i call the handler on mvc?

+1  A: 

You would use return a FileStreamResult in your action method instead of a handler.

public ActionResult GetFile()
{
    using (FileStream stream = new FileStream())
    {
        FileStreamResult result = new FileStreamResult(stream, "image/jpg");
        result.FileDownloadName = "image.jpg";
        return result;
    }
}

You could implement some resizing logic in the action.

Dustin Laine
how i use it on the page <img src="getfile/image.jpg/200/100" />?
eyalb
You reference it as a URL. `http://domain.com/Controller/GetFile` as in my example above. You could also return a `byte[]` if the file is dynamic.
Dustin Laine