Please note that version 9 is still in beta. For documentation on the latest stable release, please change to version 8.
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:

PM> install-package Piranha.Local.FileStorage

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/");
Naming

You can change how unique names are generated for uploaded media files. By default a Guid is added to the beginning of the filename in order to ensure that it is unique, but this can be changed so that files are stored in a folder with a Guid based name.

services.AddPiranhaFileStorage(naming: naming: Piranha.Local.FileStorageNaming.UniqueFolderNames);
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);