Another failed SVG upload


Another failed SVG upload

Another failed SVG upload


So, a colleague of mine had an issue where his SVG upload stopped working all of sudden. (It was no delusion - I could see older SVGs staring at me from edit mode).

However, upload stopped working with a good old Failed message. When hovering it, the error popped up: "'Parameter is not valid.'" - same as described here and normally handled as suggested here. But, this was already in place.

Changing the log file level to debug didn't help further, so we took the approach of trying to upload an SVG from code to get hold of Stack race. Super quick copy paste of Jon's (credits for the image above as well) code worked like charm and we could see that Chief2moro.ImageDataExtensions was the troublemaker. In particular, ImageResizeContentEvents.contentEvents_PublishingContent calls Dimensions imageDimensions = ImageBlobUtility.GetDimensions(image.BinaryData); and that fails badly on a vector file.

This is called on any ImageData, even though nothing is decorated with Chief2moro.ImageDataExtensions attributes. I will make a pull request to fix this; in need for a quick fix, we opted for a workaround.

Instead, we inherited from MediaData:

    [ContentType(GUID = "66DA8C3C-56A5-481C-82E5-A2C54152E314")]
    [MediaDescriptor(ExtensionString = "svg")]
    public class VectorFile : MediaData 
        public override Blob Thumbnail 
            get { return BinaryData; }

Then, SVG upload started to work. However, image thumbnails were showing a default icon, which was not such a great editorial experience. To fix this, we added a ThumbnailModelTransform that returns the default URL for a Thumbnail:

    [ServiceConfiguration(typeof(IModelTransform), Lifecycle = ServiceInstanceScope.Singleton)]
    public class ThumbnailModelTransform : StructureStoreModelTransform
        public ThumbnailModelTransform(
            IContentProviderManager contentProviderManager,
            ILanguageBranchRepository languageBranchRepository,
            IContentLanguageSettingsHandler contentLanguageSettingsHandler,
            ISiteDefinitionRepository siteDefinitionRepository,
            IEnumerable hasChildrenEvaluators,
            LanguageResolver languageResolver, UrlResolver urlResolver, TemplateResolver templateResolver) :
            contentLanguageSettingsHandler, siteDefinitionRepository,


        public override void TransformInstance(IContent source, StructureStoreContentDataModel target, IModelTransformContext context)
            base.TransformInstance(source, target, context);

            var contentWithThumbnail = source as VectorFile;
            if (contentWithThumbnail != null)
                var urlResolver = ServiceLocator.Current.GetInstance();
                var defaultUrl = urlResolver.GetUrl(contentWithThumbnail.ContentLink, null, new VirtualPathArguments { ContextMode = ContextMode.Default });
                target.ThumbnailUrl = defaultUrl;

Hope this helps someone in a similar jam!

P.S. I cannot even upload an SVG to this blogpost => Episerver definitely rocks :D


no avatar

Mark Everard SAYS:

Feb 02, 2018 at 12.26 pm

Whoops! Nice catch