resizeimageflow

.Net Core - Resizing images using Imageflow


I'm trying to resize images using Imageflow's query string API in my .net core application. I have installed Imageflow.Server. My Configure Method looks like this:

public void Configure(IApplicationBuilder App, IWebHostEnvironment Env)
    {
        if (AppSettings.IsDevelopment)
        {
            App.UseDeveloperExceptionPage();
        }
        else
        {
            App.UseExceptionHandler(Options =>
            {
                App.UseExceptionHandler("/error/404/");

            });
            App.UseHsts();
        }

        App.UseImageflow(new ImageflowMiddlewareOptions()
            .SetMapWebRoot(false)
            .MapPath("/upload/", "{upload folder path}"));

        App.UseFileServer();
        App.UseRouting();
        App.UseSession();

        App.UseEndpoints(Endpoints =>
        {
            Endpoints.MapControllers();
        });

    }

There is no problem on localhost or if the upload folder is inside the wwwroot folder, but if upload folder is outside the app root directory then images won't resize. Any Ideas how can I solve this problem?


Solution

  • If you have registered the folder as a virtual directory, IIS will prevent ASP.NET Core from serving or resizing those files.

    Unmap the virtual directory in IIS and use ASP.NET Core instead.

    To allow ASP.NET Core to serve files, call UseStaticFiles a second time to map that virtual directory: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-3.1

    You'll also still want to call MapPath on ImageflowMiddlewareOptions for the same virtual directory.