I need to check when uploading PDF files to the media folder whether the file is, let's say, by checking the "author" file property.
This is the code, I can't get the "author" property:
public class FileUploadEventHandler : INotificationHandler<MediaSavingNotification>
{
public void Handle(MediaSavingNotification notificatin)
{
foreach (var media in notificatin.SavedEntities)
{
if (media.HasProperty("author"))
{
// Get the value of the property
var propertyValue = media.GetValue<string>("author");
// Perform your accessibility check here
if (!IsFileAccessible(propertyValue))
{
notificatin.CancelOperation(new EventMessage("error",
"The file is not accessible",
EventMessageType.Error));
// File is not accessible, prevent saving the media item
}
}
}
}
private bool IsFileAccessible(string propertyValue)
{
// Implement your logic to check if the file is accessible
// Return true if the file is accessible, otherwise return false
// You can check permissions, file existence, file size, etc.
// Based on your requirements
// Example: Check if the property value is empty or null
return !string.IsNullOrEmpty(propertyValue);
}
}
pdf file properties on MediaSavingNotification
I need to check when uploading PDF files to the media folder whether the file is, let's say, by checking the "author" file property. This is the code, I can't get the "author" property:
is working on a reply...