Try our conversational search powered by Generative AI!

Triggering http handler when fetching images from BLOB storage

Vote:
 

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:

<>system.webServer>
  
    <>clear />
      <>add name="png" verb="GET,HEAD" path="*.png" type="MyProject.HttpHandler" />
      <>add name="jpg" verb="GET,HEAD" path="*.jpg" type="MyProject.HttpHandler" />
      <>add name="jpeg" verb="GET,HEAD" path="*.jpeg" type="MyProject.HttpHandler" />
      <>add name="gif" verb="GET,HEAD" path="*.gif" type="MyProject.HttpHandler" />
  handlers>
<>system.webServer>

#88922
Aug 04, 2014 13:55
Vote:
 

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?

#88924
Aug 04, 2014 14:09
Vote:
 

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.

#88926
Edited, Aug 04, 2014 14:35
Vote:
 

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 

#88927
Aug 04, 2014 14:39
Vote:
 

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.

#88928
Edited, Aug 04, 2014 14:49
Vote:
 

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 at different levels therefore the code below inherits BlobHttpHandler and not ContentMediaHttpHandler. The code in GetBlob method is the same as in ContentMediaHttpHandler

There is no need for any registration of the handler in config or so, CMS will find it from the attribute and IRenderTemplate imlementation and register it.

 [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;
        }
    }
#88930
Edited, Aug 04, 2014 15:05
Vote:
 

I got this approach to work, thanks!

#88969
Aug 05, 2014 9:56
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.