Custom MIME Types on Umbraco Cloud Resulting in 404

Has anyone had success configuring custom MIME types on Umbraco Cloud?

A client is uploading a file with an extension that .NET does not recognize (in this case, .epr) to the Media library. The upload itself completes successfully, but when attempting to access the file afterward, it results in a 404 error. The file is visible in blob storage when I connect with Azure Storage Explorer.

I have already tried registering the MIME type in the web.config:

<staticContent>
  <mimeMap fileExtension=".epr" mimeType="application/octet-stream" />
</staticContent>

And programmatically:

public class ContentTypeComposer : IComposer {
  public void Compose( IUmbracoBuilder builder ) {
    FileExtensionContentTypeProvider contentTypeProvider = new();

    if ( !contentTypeProvider.Mappings.ContainsKey( ".epr" ) ) {
      contentTypeProvider.Mappings.Add( ".epr", "application/octet-stream" );
    }

    builder.Services.Configure<StaticFileOptions>( options => options.ContentTypeProvider = contentTypeProvider );
  }
}

These approaches work as expected in a local environment, but the issue persists on Umbraco Cloud.

Has anyone encountered a similar issue or found a solution specific to Umbraco Cloud?

1 Like

Hiya
Perhaps try with a PostConfigure in case something else somewhere when booting up overrides or changes the values set for the StaticFileOptions.

This helped someone out who had a similar problem

I have done like so, in a Composer:

        builder.Services.Configure<StaticFileOptions>(options =>
        {
            var provider = new Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider();

            provider.Mappings.Add(new KeyValuePair<string, string>(".dwg", "image/x-dwg"));
            provider.Mappings.Add(
                new KeyValuePair<string, string>(".syx", "application/octet-stream")
            );
            provider.Mappings.Add(new KeyValuePair<string, string>(".tab", "text/plain"));
            provider.Mappings.Add(new KeyValuePair<string, string>(".dxf", "image/x-dxf"));

            options.ContentTypeProvider = provider;
        });
1 Like

Thanks a lot for sharing this solution. I’ve tried it on Umbraco Cloud, and it works as expected. Appreciate you taking the time to respond :umbraco-heart:

1 Like

Just be careful as think you’ll replace any other modifications by packages/composers

Below is a previous solution to just add your new ones… though I think that still has a caveat, in that it will be last past the post that wins on any duplicates..

provider.Mappings.Add would throw an error for existing duplicates.
new FileExtensionContentTypeProvider() brings 400 default mime types…

using Microsoft.AspNetCore.StaticFiles;
using Umbraco.Cms.Core.Composing;

public class RiveStaticFileComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.Services.Configure<StaticFileOptions>(options =>
        {
            var provider = options.ContentTypeProvider as FileExtensionContentTypeProvider
                           ?? new FileExtensionContentTypeProvider();
            provider.Mappings[".riv"] = "application/octet-stream";
            options.ContentTypeProvider = provider;
        });
    }
}