Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Intercepting LoadEvent on ImageData causing file upload failure.

Vote:
 

We currently have an issue in our project concerning hooking into the LoadedContent event for Images.

We have incorporated a solution described in the following blog post by Patrick Van Kleef, in order to allow images to be translatable in EPiServer.
http://www.patrickvankleef.com/2014/06/16/use-culture-specific-mediadata-properties/

For the most part the solution works, and the property values are overwritten when viewing the image in EpiServer, and rendering it via the website.
One issue we have experienced though, is if an editor wants to upload an update to the image (with the same name as the original), the update doesn't take place - the thumbnail and image are not updated with the new image.

If I look at the blobs in app_data, I can see that the new version of the image I have attempted to upload, has been written to the file system, but the thumbnail has not been created, and the image itself still points to the previous BinaryData and Thumbnail blob locations.

After debugging the code, I noticed that the issue doesn't arise from any of the translate custom code, but as soon as we create a clone of the image object. Can anyone provide a reason as to why this may happen?

Below is a cutdown version of the initialization module we use to attach to the LoadedContent event for images.

///


/// Media initialization
///

[InitializableModule]
public class MediaInitialization : IInitializableModule
{
private static readonly ILogger Logger = LogManager.GetLogger();

///


/// Initialize
///

///
public void Initialize(EPiServer.Framework.Initialization.InitializationEngine context)
{
DataFactory.Instance.LoadedContent += Instance_LoadedContent;
}

public void Uninitialize(EPiServer.Framework.Initialization.InitializationEngine context)
{
}

#region Event Handlers

///


/// Loaded content event handler
///

///
///
private void Instance_LoadedContent(object sender, ContentEventArgs e)
{
if (e.Content is IMediaTranslation)
{
var original = e.Content;
var clone = (IContent)((ImageData)original).CreateWritableClone();
e.Content = clone;
}
}

#endregion
}

I have replicated the issue in the Alloys project.

Any help or advice would be much appreciated!

Thanks,
Paul

#175758
Mar 01, 2017 11:22
Vote:
 

Why are you creating a writable clone of the image in an InitializableModule? Just curious...

#175764
Mar 01, 2017 12:40
Vote:
 

We need to be able to populate the culture specific properties of the media item with language specific, translated values. 

Without creating a writable clone, were unable to do so - the object properties are readonly.

#175773
Mar 01, 2017 15:53
Vote:
 

Might want to do that on OnPublished event instead to avoid performance problems? Might also solve your bug...

#175792
Mar 02, 2017 9:34
Vote:
 

Unfortunately that's not possible - we need to be able to present an editor with the correctly translated property values on load, in the all property view in EPiServer. 

We store the translated property values in DDS, just like the article link described in my original post.

#175796
Mar 02, 2017 11:22
* 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.