0

Recently I recevied client business requirement to get MIME Type of Multimedia Types item based on extension (External Url) from Tridion using C# Templating.

  • Read all Multimedia Types from Tridion.
  • Check Tridion Multimedia Types File Extensions with Input Extension.
  • If it`s match Multimedia Type
  • Take the MIME Type of Multimedia Type.
  • No Hard code Multimedia Type and MIME Type in C# Template code.

https://domain.com/audio/test/test_20191010.mp3 - Result (MIME Type : audio/x-mpeg) https://domain.com/video/test/test_20191002.mpg - Result (MIME Type : video/mpeg).

Looking for Ideas and Solution for above requirement.

2 Answers 2

1

Final I got solution MimeType based on file extension and code below.

> // @ExternalUrlTridionFields - Tridion ExternalUrl Field Name //
> Engine engine string FileExtension = string.Empty; string mimeType =
> string.Empty; if (Path.HasExtension(@ExternalUrlTridionFields))   //
> Checking URL Extension {
>     FileExtension = Path.GetExtension(@ExternalUrlFields);   // Get Url Extension 
>     string InputExt = FileExtension.StartsWith(".") ? FileExtension.Substring(1) : FileExtension;  // Removing dot from the
> URL File Extension (.mp3)
>     var multimediaTypes = engine.GetSession().SystemManager.GetMultimediaTypes() ;  // Read All
> Tridion MultimediaTypes  
>         foreach (var mmType in multimediaTypes)
>         {
>             List<string> FileExtensions = mmType.FileExtensions.ToList(); // Multiple multimediaTypes Extension
> in signal item
>             if (FileExtensions.Contains(InputExt))   // Checking multimediaTypes extension Contains with input extension.
>             {                                                         
>                 foreach (string FileExtension in FileExtensions)
>                 {
>                     if(FileExtension.Equals(InputExt))   // Checking multimediaType extension equal with input extension.
>                     {                                       
>                       mimeType = mmType.MimeType;  // Read multimediaType MimeType
>                     }                                                                   
>                 }
>             }
>         }              
>                      }
0

Multimedia Types include one or more file or mime types. I don't see why you need to rely on the Multimedia Type definitions for the mime types. I guess you might try to use Tridion to manage this list of mime types to extension, but I doubt they're available (at the granularity you need) over TOM.NET. Check the documentation to be sure.

If you really want to avoid hard-coding these values I'm thinking you could either inspect the mime type directly from the external item or configure these outside of your template code in a Component or some metadata.

I would just be careful that the file's actual mime type may not necessarily match the file extension.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.