Local File Storage

Last Updated: 2018-11-20

The Local File Storage handles uploaded media by storing the uploaded files on the webserver. The default directory for uploaded files is ~/wwwroot/uploads/.

As media files are stored together with the web application running the manager interface, the storage is best suited for simple applications where all components are run in the same web application. For more complex runtime scenarios a more distributed storage service is better.


The Local File Storage can be installed by adding the NuGet package:


Registering The Service

You register Local File Storage with the default configuration in ConfigureServices() with the following code:


Additional Configuration

When registering the service you have access to some configuration options to customize the storage to your needs.

Base Path

services.AddPiranhaFileStorage(basePath: "wwwroot/media");

The path where media files are uploaded. The default value is wwwroot/uploads.

Base Url

services.AddPiranhaFileStorage(basePath: "wwwroot/media", baseUrl: "~/media/");

The base url where local files can be downloaded. Please note that there's no rewriting made for requested URL's so the provided value must match the structure of the file system. The default value is ~/uploads/.


services.AppPiranhaFileStorage(scope: ServiceLifetime.Scoped);

By default the service is registered as a Singleton, but in some cases you might want to handle it differently in your application.