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

Advertisements

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