Access Files
Folders and file information are stored in regular collections, which means user and role access permissions are fully configurable and granular on both folders and files.
The location of your actual file originals is based on the project's configuration, but you can consistently access them via the API using the following URL:
https://example.com/assets/<file-id>
https://example.com/assets/1ac73658-8b62-4dea-b6da-529fbc9d01a4
Authentication
Directus leverages stored cookies to authenticate when accessing files, when present.
If no cookie is stored, you can use the access_token
query parameter to authenticate, provided the token belongs to a user with the required access to read the file.
SEO
You can provide an optional filename after the UUID to optimize for SEO, for example:
https://example.com/assets/<file-id>/<filename>
https://example.com/assets/1ac73658-8b62-4dea-b6da-529fbc9d01a4/directus-logo.png
This optional filename is also used in the Content-Disposition
header when the ?download
query parameter is used.
While you may technically be able to expose your storage adapters root file system and access your raw files through there, it is recommended that you always use the Directus API. This is the only way that you can take advantage of file permissions and other built-in features.
Downloading a File
To download an asset with the correct filename, you need to add the ?download
query parameter to the request and the
download
attribute to your anchor tag. This will ensure the appropriate
Content-Disposition headers are added. Without this, the
download will work on the same domain, however it will have the file's "id" as the filename for cross-origin requests.
Fetching transformed assets is done by adding a key
query parameter to the original file's URL. In the Data Studio, you can
configure different asset presets that control the output of any given image. If a requested transformed asset doesn't yet
exist, it is dynamically generated and immediately returned.