umbraco / Umbraco.StorageProviders

MIT License
29 stars 21 forks source link

Allow configuring file extension mappings #50

Closed Swimburger closed 2 years ago

Swimburger commented 2 years ago

Prior to Umbraco 10, I was able to use the following snippet to serve static avif-files from my wwwroot folder:

var provider = new FileExtensionContentTypeProvider();
provider.Mappings[".avif"] = "image/avif";
app.UseStaticFiles(new StaticFileOptions
{
    ContentTypeProvider = provider
});

In Umbraco 10, this breaks the ImageSharp integration with Umbraco, so I can't resize images, crop, convert, etc. via the URL.

How do we achieve the same in Umbraco 10?

Swimburger commented 2 years ago

This used to not matter I guess, but now you gotta make sure to put that code after your call to UseUmbraco. After doing that, both started working:

        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // breaks ImageSharp integration, put below
            //var provider = new FileExtensionContentTypeProvider();
            //provider.Mappings[".avif"] = "image/avif";
            //app.UseStaticFiles(new StaticFileOptions
            //{
            //    ContentTypeProvider = provider
            //});

            app.UseUmbraco()
                .WithMiddleware(u =>
                {
                    u.UseBackOffice();
                    u.UseWebsite();
                })
                .WithEndpoints(u =>
                {
                    u.UseInstallerEndpoints();
                    u.UseBackOfficeEndpoints();
                    u.UseWebsiteEndpoints();
                });

            var provider = new FileExtensionContentTypeProvider();
            provider.Mappings[".avif"] = "image/avif";
            app.UseStaticFiles(new StaticFileOptions
            {
                ContentTypeProvider = provider
            });
        }