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
2010-10-26 21:02:27
how i use it on the page <img src="getfile/image.jpg/200/100" />?
eyalb
2010-10-26 21:13:38
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
2010-10-26 21:15:45