.Net Core - Resizing images using Imageflow

752 Views Asked by At

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?

2

There are 2 best solutions below

1
On BEST ANSWER

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.

12
On

This could be a permissions issue. If on-disk permissions do not allow the user account running the app to access the folder, it will fail.