Contribute to Docs Contribute to Docs

Local File Storage

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.

Installation

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

<PackageReference Include="Piranha.Local.FileStorage" Version="7.0.0" />

Registering The Service

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

services.AddPiranhaFileStorage();

Additional Configuration

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

Base Path

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

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

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.AddPiranhaFileStorage(basePath: "wwwroot/media", baseUrl: "~/media/");
Scope

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

services.AppPiranhaFileStorage(scope: ServiceLifetime.Scoped);