Skip to main content

Store files on the local file system

This guide explains how to store uploaded files on the file system of the Casdoor server. Casdoor stores them in its files directory. For example, if Casdoor runs in /home/user/casdoor, the files are in /home/user/casdoor/files.


Learning outcomes​

  • Add a local file system storage provider.
  • Choose a path prefix.

What you need​

  • Administrator access to the Casdoor admin console

Add the provider​

  1. In the Casdoor admin console, go to Identity > Providers and add a provider.

  2. Set Category to Storage and Type to Local File System.

    Local file system provider

  3. Optionally, set Path prefix. Casdoor then stores the files in a subdirectory with that name.

  4. Save the provider.

With a path prefix:

Provider with a path prefix

Files stored under the prefix

Without a path prefix:

Provider without a path prefix

Files stored without a prefix

note

In a container, mount the files directory on a volume. Otherwise, the files are lost when the container is replaced.

How files are served​

Casdoor serves the files of this provider under the path /files/, for example https://<your-casdoor-host>/files/<path-prefix>/<file-name>. To keep an uploaded file from running script on the domain of Casdoor, it sends every file that exists there with these response headers:

HeaderEffect
X-Content-Type-Options: nosniffThe browser doesn't guess another content type from the content of the file
Content-Security-Policy: default-src 'none'; sandboxA file that the browser opens directly loads nothing and runs no script
Content-Disposition: attachmentOnly for active content: the browser downloads the file instead of showing it. Active content is a file with the extension .htm, .html, .mht, .mhtml, .svg, .svgz, .swf, .xht, .xhtml, .xml, .xsl, or .xslt, without regard to case

Images in an <img> tag, such as avatars, still show, because the browser ignores these headers there. A path under /files/ that doesn't exist returns the Casdoor web application with its usual headers.

See also​