Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Jesper Weber 33 posts 98 karma points c-trib
    Feb 23, 2021 @ 14:39
    Jesper Weber
    0

    Set ContentType in MediaService.Saving event

    Hi,

    I have created a custom media type and hooked in to the MediaService.Saving event.

    When a file is uploaded I want to set the content type based on the file extension. How ever at that point Umbraco has already given media a content type.

        public void Initialize()
        {
            MediaService.Saving += MediaService_Saving;
        }
    
        private void MediaService_Saving(IMediaService sender, SaveEventArgs<IMedia> e)
        {
            foreach (var mediaItem in e.SavedEntities)
            {
                var contentTypeAlias = mediaItem.ContentType.Alias;
            }
        }
    

    How do I change the content type or hook in earlier to set the content type my self?

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies