Copied to clipboard

Flag this post as spam?

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


  • Jakob Lithner 61 posts 264 karma points
    Mar 07, 2016 @ 11:33
    Jakob Lithner
    0

    Upload area accepts not allowed media types

    I have created two custom Media Types: Audio and AudioFolder. Audio has all needed properties for displaying audio files. AudioFolder is limited to allow only Audio and AudioFolder as children. The create button limits new items as expected. The AudioFolder has a property called Content with list view. Above that list is the default upload area visible to pick files from disk. The problem is that dialog accepts any file which contradicts the rule I just set! That way files can be uploaded without being the required Audio type, which means they miss all my custom properties.

    enter image description here

    In ApplicationStarted I have added a MediaService.Saving event handler to check the uploaded file. In case of Audio file I parse entered Media properties and add them as MP3 tags to file for consistency. But when the file is uploaded through the upload area it has the default MediaType of "File". Is it possible to convert that IMedia to the right type on the fly, exposing the properties from custom Audio type? The upload area is easy to use, so I really would like a solution along that line.

    Another workaround would be to turn off the upload area, but I don't know if that is possible.

  • Jakob Lithner 61 posts 264 karma points
    Mar 07, 2016 @ 12:10
    Jakob Lithner
    0

    I found the solution! The MediItem has a method called ChangeContentType that does the trick.

    var contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
    var audioMediaType= contentTypeService.GetMediaType("audio");
    mediaItem.ChangeContentType(audioMediaType);
    
Please Sign in or register to post replies

Write your reply to:

Draft