mediaItem.GetValue - umbracoWidth umbracoHeight sometimes return null values
We're hooking some code into MediaService.Saving in order to check if an image is over a certain width or height, and if so resizing it to be smaller. In order to perform the check, we get the values umbracoWidth and umbracoHeight of the image being uploaded.
However, every so often those values are randomly null, which causes our code to error out. Attached is a sample image that's giving trouble, our modified code in Events/MediaEvents.cs, and a screenshot of the error.
private void MediaService_Saving(Umbraco.Core.Services.IMediaService sender, Umbraco.Core.Events.SaveEventArgs<Umbraco.Core.Models.IMedia> e)
{
int width = int.Parse(WebConfigurationManager.AppSettings["ImageResizeWidth"]);
int height = int.Parse(WebConfigurationManager.AppSettings["ImageResizeHeight"]);
string fileNameSuffix = WebConfigurationManager.AppSettings["ImageResizeSuffix"];
foreach (var mediaItem in e.SavedEntities)
{
if (!string.IsNullOrEmpty(mediaItem.ContentType.Alias) && mediaItem.ContentType.Alias == "Image")
{
bool isNew = !mediaItem.HasIdentity;
int currentWidth = int.Parse(mediaItem.GetValue("umbracoWidth").ToString());
int currentHeight = int.Parse(mediaItem.GetValue("umbracoHeight").ToString());
mediaItem.GetValue - umbracoWidth umbracoHeight sometimes return null values
We're hooking some code into MediaService.Saving in order to check if an image is over a certain width or height, and if so resizing it to be smaller. In order to perform the check, we get the values umbracoWidth and umbracoHeight of the image being uploaded.
However, every so often those values are randomly null, which causes our code to error out. Attached is a sample image that's giving trouble, our modified code in Events/MediaEvents.cs, and a screenshot of the error.
is working on a reply...