Setting up Azure CDN to deliver your Sitecore Media

At SUGCON EU 2016 I presented about the different options of using Content Delivery Networks with Sitecore. At the time, I had been working on a particular task to offload large media items into Azure Blob storage and serve them to via Azure CDN and wrote a number of posts detailing how I achieved this.

One of the options that I presented was utilising Azure CDN to serve your media, allowing you to benefit from Azure’s Geo-located Edge Servers meaning that assets are served from locations closer to your users, your own servers can focus on just delivering content (possibly meaning less content delivery servers and licensing costs) as well as improving browser response times by domain sharding the requests.

Use of Azure CDN will work with any version of Sitecore, and is not specific to Sitecore 8.2 Update-1 which added Azure Web Apps support. In fact, you don’t even need to be hosting your servers in Azure to utilise the CDN service.

I’ve been asked by several Sitecorians about configuring CDN, so I thought I would share a step-by-step guide in setting up Azure CDN with Sitecore.

there-is-no-cloud

Read More

Mass Uploading Media

Have you ever had the need to mass upload media into Sitecore? Maybe you are migrating to Sitecore or your editors now want to upload a big set of images into the media library. Tired of Right Click > Insert > Upload File over and over again?

Sweet Brown

There are some built-in ways in Sitecore to easily do this.

Read More

Storing Files in Azure Cloud Storage through the Sitecore Media Library – Part 3 – Attach Media Handler

This wasn’t supposed to be a blog post series, and my original reason for this code was to just offload the hosting of large files. But whilst writing the first draft of the blog post I started to investigate various areas since the potential for this module became greater. It was supposed to stop at part two, but I supposed I suffer from the same thing as most of you: programmers OCD. And so a series is born and expect another post or two to follow until a final solution is attained.

In my previous code I noted that the code did not work with the attach/detach handlers in the Media Library:

Media-Attach-Handler

Read More

Storing Files in Azure Cloud Storage through the Sitecore Media Library – Part Two – Link Management

This is a continuation of my previous blog post in which we uploaded files into Azure Blob Storage through the Sitecore Media Library. If you haven’t read it yet then first go and do that since this may not make much sense otherwise…

The previous post showed how to upload media files into Azure Blob Storage using a custom pipeline. I started off the post by stating that the requirement was to only store large files in Azure and that was primarily the focus of what we needed to achieve but some small tweaks meant it was possible to store all media in Cloud storage.

We still need to make some small updates to code to allow us to actually correctly link to the media in Azure though, so I’ll present a couple of options we have to do that.

Read More

Storing Files in Azure Cloud Storage through the Sitecore Media Library – Part One – Uploading Files

On a recent project we had the requirement to be able to link to large files which the user would be able to download, file sizes could be up to 2GB in size. Far too large to store in Sitecore Media Library, at least in database storage. We had previously used Blob storage in Azure with great success for another (non-Sitecore) site so decided to utilise this again but wanted a seamless, single interface for the user to work with, i.e. everything through Sitecore.

Knowing that Azure has a rich API set and pretty much everything in Sitecore can be hacked into via the pipelines we set on our merry journey.

The following requirements were set in order to help set the boundaries:

  • any file uploaded to certain folders would be uploaded to Azure
  • any file uploaded and the “Upload as Files” option checked would be uploaded to Azure Blob Storage

There was also an additional requirement to automatically calculate the MD5 of each file which was uploaded. This ties in follows on nicely from my previous post about extending Media Item templates using Glass Mapper. Hopefully the specifics of that post will make more sense after this as well 🙂

Read More

SVG in Media Library Polluting Log Files with Errors

Storing SVGs in the Sitecore Media Library is pretty simple, just add a new mediatype in config. This has been well documented and there are several posts as well as Stackoverflow/forum answers for this. e.g. https://community.sitecore.net/developers/f/8/t/1670

And this works fine and everything renders great, but whilst trying to sort out some servers issues and trawling through the Sitecore logs I noticed it was littered with Errors like so:

5920 15:34:49 ERROR Could not run the 'getMediaStream' pipeline for '/sitecore/media library/github-logo-01'. Original media data will be used.
Exception: System.ArgumentException
Message: Parameter is not valid.
Source: System.Drawing
   at System.Drawing.Bitmap..ctor(Stream stream)
   at Sitecore.Resources.Media.ImageEffectsResize.ResizeImageStream(Stream inputStream, TransformationOptions options, ImageFormat outputFormat)
   at Sitecore.Resources.Media.ImageThumbnailGenerator.GetStream(MediaData mediaData, TransformationOptions options)
   at Sitecore.Resources.Media.MediaData.GetThumbnailStream(TransformationOptions options)
   at Sitecore.Resources.Media.ThumbnailProcessor.Process(GetMediaStreamPipelineArgs args)
   at (Object , Object[] )
   at Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args)
   at Sitecore.Resources.Media.Media.GetStreamFromPipeline(MediaOptions options, Boolean& canBeCached)

Read More

Force Download and Prompt User to Save Media from the Sitecore Media Library

Recently on Slack Chat a question got asked by fellow MVP Jason Bert about how to prompt a user to save an item from the Sitecore Media Library. Whether a user is prompted to download media depends on a few factors:

  • Whether the browser or an associated plugin understands how to process that mime type
  • Settings under mediaLibrary\mediaTypes in the Sitecore section of config
  • The response headers sent by the server, and whether Content-Disposition=attachment

It’s this final header which we need to add ourselves in the Response headers. I shared some code but was pretty surprised when it did not work. Previously in an earlier version of Sitecore I had simply tapped into the getMediaStream pipeline and then set Content-Disposition=true header based on a url parameter. Something had obviously changed, or I was going mad. Most likely a combination of both…

Read More

Custom Glass.Mapper Data Handlers – Part 2

In a previous post about extending Glass Mapper to handle custom data types I shared some code which I felt was overly verbose and I did not like the amount of code that had been copy/pasted. The example I used was a fairly trivial one, but it’s always good practice to try avoid copy/paste in case some point in the future the base implementation is changed. It might not always be clear to future developers how that piece of code had come about.

In that original post, Mike Reynolds (a.k.a sitecorejunkie) suggested use of the Decorator Pattern to wrap an instance of the base mapper and delegate some of the methods. Well it got me feeling uneasy and I finally found a little time to come back and clean that code up, I went a slightly different route and decided to use constructor overloading.

Read More

Extending Media Item Templates with Custom Glass.Mapper Data Handlers

On a recent project I needed to add a couple of fields to Media Items templates in order store some additional data. We are using the Glass Mapper ORM in our project and out of the box there are two fields which we can map to: Image and File. I also needed to retrieve the file size, which neither of these fields returned either.

It turned out to be relatively simple to extend Glass Mapper and add our own custom data handler to map the additional fields.

Read More

Issues opening PDF files in IE9 from Sitecore Media Library

tl;dr A bug in the Adobe Reader plugin causes IE9 to not load PDF files in the browser, which can be fixed by disabling chunked transfer encoding in Sitecore config.

About 5 months ago we upgraded a Sitecore 6.4 solution to 7.0. I can’t remember why we didn’t go with 7.1 since it had been released, but I think it may have been because some of the modules we were using (mainly WFFM and ECM) were not ready at the time. Regardless, the issue we faced would have been the same.

The site we were working on was very media heavy – lots of images and PDFs (in fact this was an ideal candidate for CDN, but that’s another story…). During testing we were getting reports of the links to PDF’s no longer working, but intermittently and only for some people. Eventually we narrowed it down to IE9 browsers only.

Read More