Hi
IContentMedia is a sort of IContent and are routed to in the same way as e.g. pages. That is it is the routing system in EPiServer CMS that routes the url to an IContentMedia instance. And in same matter as for other types of IContent (pages, blocks) is it then the TemplateResolver that decides how the content should be rendered/handled. By default is IContentMedia instances handled by an instance of EPiServer.Web.ContentMediaHttpHandler.
What is it that you want to achieve?
We want to have some server side image resizing, and in epi 6 we did this via a handler. I'm porting it to epi 7.5, but I can't get this bit to work.
We send the desired format in the querystring added to the request for the image.
You can use attributes to get image resizing. See e.g.
http://www.markeverard.com/2014/02/13/image-resizing-in-episerver-7-5-cms/
or http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=81210
We have a sort of special setup in our case. We have a gallery, and all the children pages of that gallery page contains the entries. When we load the gallery, we get all the children, get the urls for the images, and send them to the client as json. So we dont render the images directly from the property. The attribute doesn't seem to work in this case.
And we need the images in both the original and resized sizes. If we request a resized image, we get the resized one. If not, the request just goes through as usual.
I am not sure I fully understand your scenario but it is possible to register a custom http handler for a certain subtype. E.g. in your case you can register it for IContentImage.
There is a bug that you can not have inherited classes that implements IRenderTemplate
There is no need for any registration of the handler in config or so, CMS will find it from the attribute and IRenderTemplate
[TemplateDescriptor(Inherited = true, TemplateTypeCategory = TemplateTypeCategories.HttpHandler)]
public class CustomImageHttpHandler : BlobHttpHandler, IRenderTemplate
{
protected override Blob GetBlob(HttpContextBase httpContext)
{
//This the implementation from ContentMediaHttpHandler
var downLoadFileName = httpContext.Request.RequestContext.GetCustomRouteData(DownloadMediaRouter.DownloadSegment);
if (!string.IsNullOrEmpty(downLoadFileName))
{
httpContext.Response.AppendHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", downLoadFileName));
}
var routeHelper = ServiceLocator.Current.GetInstance();
var binaryStorable = routeHelper.Content as IBinaryStorable;
return binaryStorable != null ? binaryStorable.BinaryData : null;
}
}
I have a http handler that seems to trigger on everything - except on the images that are fetched from BLOB storage.
Does anyone know why? Is there something special about the content from the BLOB storage?
The handlers is added like this: