Last updated
Was this helpful?
Last updated
Was this helpful?
Filesystem providers are configured via code, you can either configure it in a composer, or in the Program.cs
file.
By default Umbraco will save Media in a folder called /media
within the webroot on the Physical file system. The code snippet above will change the location to instead save the media in a folder called /CustomMediaFolder
within the webroot.
The media provider can be of many types, for example in case you want to store media on Azure, Amazon or even DB. But the provider that comes by default with the installation of Umbraco is the PhysicalFileSystem
provider.
The physical file system provider manages the interaction of Umbraco with the local file system. It can be configured for two different scenarios:
Media files stored inside a virtual folder of the site
Media files stored somewhere else outside of the site and accessed via a custom URL
There are a few more steps involved if you want to store the media files in a separate folder outside the webroot.
First you must register the folder as a static file provider in your Program.cs
file like so:
Now you can register the folder as the media filesystem
This is much the same as when you register it within the wwwroot with a virutal folder. The only differnce is that now you provide an absolute root path and root URL to the physical filesystem.
rootPath
is the full filesystem path where you want media files to be stored. It has to be rooted, must use directory separators (\
) and must not end with a separator. For example, Z:
or C:\path\to\folder
or \\servername\path
.
rootUrl
is the URL where the files will be accessible from. It must use URL separators (/
) and must not end with a separator. It can either be a folder, like /UmbracoMedia
, in which case it will considered as subfolder of the main domain (example.com/UmbracoMedia
) or can be a fully qualified URL, with also domain name and protocol (for ex http://media.example.com/media
).
The recommended approach to obtain a file's content as a stream is to utilize the MediaFileManager
. It is advised to avoid reading the file directly from the server using methods like Server.MapPath
. This will ensure that, regardless of the file system provider, the stream will be returned correctly. This example demonstrates using MediaFileManager to validate file existence and stream it back from a controller.
To configure the PhysicalFileSystem for a virtual folder, create a new filesystem with a root path and URL within the wwwroot folder. Refer to the example above and for more information.
For more information see .
To store media files in different systems, the type of provider must be changed. You can learn in the Extending Umbraco section.
Information on FileSystemProviders and how to configure them in Umbraco