MediaService Notifications Example
Example of how to use a MediaService Notification
Usage
using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;
namespace MySite;
public class MediaNotificationHandler : INotificationHandler<MediaSavedNotification>
{
private readonly ILogger<MediaNotificationHandler> _logger;
public MediaNotificationHandler(ILogger<MediaNotificationHandler> logger)
{
_logger = logger;
}
public void Handle(MediaSavedNotification notification)
{
foreach (var mediaItem in notification.SavedEntities)
{
if (mediaItem.ContentType.Alias.Equals("Image"))
{
// Do something with the image, maybe send to Azure for AI analysis of image contents or something.
_logger.LogDebug($"Sending {mediaItem.Name} to analysis");
SendToAzure(mediaItem);
}
}
}
}Returning messages to the user
Example
Last updated
Was this helpful?