Media types => not included?

Hello!

I want to be able to use a specific type of file extension called .step

I suspect that I need to add those to the Media => Field Templates => Other but I’m rather unsure as to where to do so since they don’t exist in the list of options here to pick from.

Any tips/help with this would be greatly appreciated.

Regards, Karwan.

Hi,

We are looking into a solution for this. Most probably we will introduce a way for partners to define allowed file types for a project, by specifying a list in app settings.

Best regards,

Ludvig

1 Like

@ludvig.block Is there any workaround we can do right now?

We are going really short on time right now and this is blocking a release on our side. Worst case is that we need to downgrade the upgrade we have done, I’m not even sure if that’s possible to do?

The only workaround is to use the internal APIs of Litium Platform, see Add custom file extension to media field template - Questions - Litium Forum

Do we have any better examples other than the one seen in the ticket?

Because I’ve tried with that already and I’m not going anywhere with it.

Okay so after some head scratching this is what I’ve done so far:

  • I created this class to extend the MimeTypes.
using System.Collections.Generic;
using Litium.Application.Media;
using Microsoft.Extensions.Logging;

namespace Litium.Accelerator.Mvc.Extensions
{
    public class ExtendedMimeExtensionHelper : MimeExtensionHelper
    {
        private readonly List<MimeTypeInfo> _customMimeTypes = new List<MimeTypeInfo>
        {
            new MimeTypeInfo("application/step", new List<string> { ".step" }),
            new MimeTypeInfo("application/sldasm", new List<string> { ".sldasm" }),
            new MimeTypeInfo("application/sldprt", new List<string> { ".sldprt" })
        };

        public ExtendedMimeExtensionHelper(ILogger<MimeExtensionHelper> logger) : base(logger) { }

        public override string FindExtension(string mimeType)
        {
            foreach (var customMimeType in _customMimeTypes)
            {
                if (mimeType == customMimeType.MimeType)
                    return customMimeType.Extensions[0];
            }

            return base.FindExtension(mimeType);
        }

        public override string FindMime(string extension)
        {
            foreach (var customMimeType in _customMimeTypes)
            {
                if (customMimeType.Extensions.Contains(extension))
                    return customMimeType.MimeType;
            }

            return base.FindMime(extension);
        }

        public override IEnumerable<MimeTypeInfo> GetAll()
        {
            var baseList = new List<MimeTypeInfo>(base.GetAll());
            baseList.AddRange(_customMimeTypes);
            return baseList;
        }
    }
}
  • And then I added it into the startup.

          services.AddSingleton<MimeExtensionHelper, ExtendedMimeExtensionHelper>();
    

Do I need to do something else? Like do I need to actually ignore the original MimeType in the appsettings?

By doing this I was able to upload the file that I wanted to upload but I want to make sure of that I don’t break anything later on. :slight_smile:

You need to add the default class into the litium/plugin/types/remove section in the appsettings, otherwise it will still be used.

1 Like

I’ve done so now. Thanks for the help.

In Litium 8.12.0 that will plan to release today we have added support to configure additional extensions in appSettings.json as

  "Litium": {
    "Media": {
      "MimeTypes": {
        ".step": "image/step"
      }
    }
  }
2 Likes

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.