How can I extend Umbraco media picker to overwrite the file if same name file is uploaded?
In image above It creates two file but I want first one to be replaced with new file.
I am using umbraco 7.11.1
How can I extend Umbraco media picker to overwrite the file if same name file is uploaded?
In image above It creates two file but I want first one to be replaced with new file.
I am using umbraco 7.11.1
Have you tried creating an ApplicationEventHandler and hooking into one of the media events listed here: https://our.umbraco.com/Documentation/Reference/Events/MediaService-Events Then you could compare the file the user is attempting to upload vs what is already in the media cache.
e.g.
public class MediaSaving : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase
umbracoApplication, ApplicationContext applicationContext)
{
MediaService.Saving += MediaServiceSaving;
}
void MediaServiceSaving(IMediaService sender, SaveEventArgs<IMedia> evt)
{
foreach (var mediaItem in evt.SavedEntities)
{
//Check if a new upload and correct type etc
//Compare file paths and overwrite if appropriate
}
}
}