AI OnAI Off
I've done the following for saving the file size, guess you could do something similar to populate Height and Width.
[InitializableModule] [ModuleDependency(typeof(EPiServer.Web.InitializationModule))] public class FileInitialization : IInitializableModule { public void Initialize(InitializationEngine context) { var eventRegistry = ServiceLocator.Current.GetInstance<IContentEvents>(); eventRegistry.CreatingContent += OnCreatingContent; eventRegistry.SavingContent += OnSavingContent; } private void OnSavingContent(object sender, ContentEventArgs e) { var content = e.Content as MediaData; if (content == null || !(content is ISearchableFile)) return; var fs = content.GetFileSize(); ((ISearchableFile)content).FileSizeInKb = (int)fs; } private static void OnCreatingContent(object sender, ContentEventArgs e) { var content = e.Content as MediaData; if (content == null || !(content is ISearchableFile)) return; var fs = content.GetFileSize(); ((ISearchableFile)content).FileSizeInKb = (int)fs; } }
I would go with Erik's approach. Mark Everard has a good example on how to get the dimensions: https://github.com/markeverard/Chief2moro.ImageDataExtensions/blob/master/src/Chief2moro.ImageDataExtensions/ImageBlobUtility.cs
Also, I would add the [Editable(false)] attribute to the properties, as this would be read-only properties.
This is awesome! exactly what I was looking for.
Thanks guys! Thanks a lot!
I need to have some properties on my images like their original size (width and height), so I've inherited from ImageData like this:
But of course those files are not filled. How can I fill them everytime someone uploads an image, or edit the one related?
I was hoping to find a class that I can extend for this but ContentMediaHttpHandler that has been mentioned in the documentation is not there and I don't like to implement a media handler from scratch.
Where shall I fill the fileds?