Responsive File Manager for ASP.NET Core

Matt Gordon, Jakub Misek Free   Connect to feed
The whole of Responsive File Manager, compiled, packed and provided as an ASP.NET Core package. Does not require PHP, becomes a part of ASP.NET Core application.

Donate

Peachpie Responsive File Manager

peachpie-responsive-file-manager

Responsive File Manager running on .NET Core with Peachpie

Getting Started

If you are not already using Peachpie for anything, then including Responsive File Manager is very easy:

  1. Get the ResponsiveFileManager.AspNetCore NuGet package from: https://www.nuget.org/packages/ResponsiveFileManager.AspNetCore/

  2. Add the following to your appsettings.json:

"ResponsiveFileManagerOptions": {
    // Path from base_url to base of upload folder. Use start and final /
    "UploadDirectory": "/Media/Uploads/",

    // Relative path from filemanager folder to upload folder. Use final /
    "CurrentPath": "../Media/Uploads/",

    // Relative path from filemanager folder to thumbs folder. Use final / and DO NOT put inside upload folder.
    "ThumbsBasePath": "../Media/Thumbs/",
	
    "MaxSizeUpload":  10
}
  1. Add ResponsiveFileManager as middleware within the Configure method:
app.UseResponsiveFileManager();
  1. Optionally configure ResponsiveFileManager settings in the ConfigureServices method.
services.AddResponsiveFileManager(options =>
{
	
});

If you are wanting to use Peachpie for more than just ResponsiveFileManager, then it is recommended you ignore the ResponsiveFileManager.AspNetCore package, only acquire the base ResponsiveFileManager package and then manually configure the settings as follows:

  1. Get the ResponsiveFileManager NuGet package from: https://www.nuget.org/packages/ResponsiveFileManager/

  2. Create the following class:

public class ResponsiveFileManagerOptions
{
    /// <summary>
    /// Path from base_url to base of upload folder. Use start and final /
    /// </summary>
    public string UploadDirectory { get; set; }

    /// <summary>
    /// Relative path from filemanager folder to upload folder. Use final /
    /// </summary>
    public string CurrentPath { get; set; }

    /// <summary>
    /// Relative path from filemanager folder to thumbs folder. Use final / and DO NOT put inside upload folder.
    /// </summary>
    public string ThumbsBasePath { get; set; }

    /// <summary>
    /// Maximum upload size in Megabytes.
    /// </summary>
    public int? MaxSizeUpload { get; set; }
}
  1. Add the following to your appsettings.json:
"ResponsiveFileManagerOptions": {
    // Path from base_url to base of upload folder. Use start and final /
    "UploadDirectory": "/Media/Uploads/",

    // Relative path from filemanager folder to upload folder. Use final /
    "CurrentPath": "../Media/Uploads/",

    // Relative path from filemanager folder to thumbs folder. Use final / and DO NOT put inside upload folder.
    "ThumbsBasePath": "../Media/Thumbs/",
	
    "MaxSizeUpload":  10
}
  1. Open your Startup.cs and ensure it looks something like this:
public void ConfigureServices(IServiceCollection services)
{
    // etc
	
    // Adds a default in-memory implementation of IDistributedCache.
    services.AddDistributedMemoryCache();

    services.AddSession(options =>
    {
        options.IdleTimeout = TimeSpan.FromMinutes(30);
        options.Cookie.HttpOnly = true;
    });
	
    // etc
}

public void Configure(IApplicationBuilder app)
{
    // etc

    app.UseSession();

    var rfmOptions = new ResponsiveFileManagerOptions();
    Configuration.GetSection("ResponsiveFileManagerOptions").Bind(rfmOptions);

    app.UseDefaultFiles();
    app.UseStaticFiles(); // shortcut for HostEnvironment.WebRootFileProvider
    app.UseStaticFiles(new StaticFileOptions
    {
        RequestPath = new PathString("/filemanager"),
        FileProvider = new PhysicalFileProvider(Path.GetFullPath(Path.Combine(Assembly.GetEntryAssembly().Location, "../filemanager"))),
    });

    app.UsePhp(new PhpRequestOptions(scriptAssemblyName: "ResponsiveFileManager")
    {
        BeforeRequest = (Context ctx) =>
        {
            ctx.Globals["rfm_options"] = PhpValue.FromClass(rfmOptions);
        }
    });

    // etc
}

You can use the source code in this repo, as follows:

  1. Open the solution in Visual Studio 2017 or newer.
  2. Set the WebApplication project as the default, if it isn't already.
  3. restore libs in WebApplication folder:
  • dotnet tool install -g Microsoft.Web.LibraryManager.Cli
  • libman restore
  1. Run and test one of the demo pages
  2. Look at the Startup.cs file for configuration to copy to your own project to use with the NuGet package.

Donate

If you find this project helpful, consider buying me a cup of coffee. 😃

PayPal:

paypal

Crypto:

  • Bitcoin: 1EeDfbcqoEaz6bbcWsymwPbYv4uyEaZ3Lp
  • Ethereum: 0x277552efd6ea9ca9052a249e781abf1719ea9414
  • Litecoin: LRUP8hukWGXRrcPK6Tm7iUp9vPvnNNt3uz

More information

ResponsiveFileManager.AspNetCore
1.3.2
10/5/2020
github.com/gordon-matt/peachpie-responsive-file-manager

Share