Skip to main content

Storage back ends

Each storage back end is configured under dari/storage/{name} in your Dari settings, where {name} is an arbitrary identifier you choose. Set dari/defaultStorage to the name of the back end you want to use by default.

Common settings

All back ends that extend AbstractStorageItem support these settings:

SettingDescription
classFully qualified class name of the StorageItem implementation.
baseUrlBase URL for constructing public URLs.
secureBaseUrlBase URL for constructing secure (HTTPS) public URLs.
baseUrlsMap of multiple base URLs for multi-CDN distribution.
secureBaseUrlsMap of multiple secure base URLs for multi-CDN distribution.
hashAlgorithmName of the StorageItemHash to use for distributing requests across baseUrls.
originBaseUrlBase URL for constructing origin URLs (bypasses CDN).
tip

When both baseUrl and baseUrls are set, baseUrl takes precedence. Use baseUrls with hashAlgorithm for multi-CDN setups where you want to distribute assets across multiple domains.

Local filesystem

Stores files directly on the server's filesystem. Useful for development and single-server deployments.

Class: com.psddev.dari.util.LocalStorageItem

SettingRequiredDescription
rootPathYesAbsolute path to the directory where files are stored.
originBaseUrlNoBase URL for origin access.

Example configuration:

1
dari/defaultStorage=local
2
dari/storage/local/class=com.psddev.dari.util.LocalStorageItem
3
dari/storage/local/rootPath=/servers/tomcat/storage
4
dari/storage/local/baseUrl=http://localhost/storage

Amazon S3

Stores files in an Amazon S3 bucket using the AWS SDK v2.

Class: com.psddev.dari.aws.S3StorageItem

Artifact: com.brightspot.storage:aws

SettingRequiredDescription
bucketYesS3 bucket name. Can include a path prefix (e.g., my-bucket/prefix).
cannedACLNoThe ObjectCannedACL to apply to uploaded objects. Defaults to PUBLIC_READ.
originBaseUrlNoBase URL for origin access (bypasses CDN).

Example configuration:

1
dari/defaultStorage=s3
2
dari/storage/s3/class=com.psddev.dari.aws.S3StorageItem
3
dari/storage/s3/bucket=my-bucket
4
dari/storage/s3/baseUrl=https://cdn.example.com
5
dari/storage/s3/secureBaseUrl=https://cdn.example.com
note

AWS credentials are resolved using the default credential provider chain. You do not need to configure access keys in Dari settings—use environment variables, IAM roles, or shared credential files instead.

Bucket path prefix

The bucket setting supports a path prefix separated by /. For example, my-bucket/media stores all files under the media/ prefix within my-bucket.

Access control

The cannedACL setting accepts any value from software.amazon.awssdk.services.s3.model.ObjectCannedACL:

  • PUBLIC_READ (default)
  • PRIVATE
  • AUTHENTICATED_READ
  • BUCKET_OWNER_FULL_CONTROL
  • BUCKET_OWNER_READ
  • AWS_EXEC_READ

You can also change permissions on individual objects programmatically:

1
storageItem.updatePermission(true); // make private
2
storageItem.updatePermission(false); // make public

Azure Blob Storage

Stores files in Azure Blob Storage containers.

Class: com.psddev.azure.storage.AzureBlobStorageItem

Artifact: com.brightspot.storage:azure

SettingRequiredDescription
accountNameYes*Azure storage account name. Required unless endpoint is set.
accountKeyNoAzure storage account key. If omitted, uses DefaultAzureCredential.
containerYesName of the blob container. Created automatically if it doesn't exist.
endpointNoCustom endpoint URL. Overrides the default https://{accountName}.blob.core.windows.net/ endpoint.
disablePublicReadNoSet to true to disable public blob-level read access. Defaults to false.
originBaseUrlNoBase URL for origin access.

Example configuration:

1
dari/defaultStorage=azure
2
dari/storage/azure/class=com.psddev.azure.storage.AzureBlobStorageItem
3
dari/storage/azure/accountName=mystorageaccount
4
dari/storage/azure/container=media
5
dari/storage/azure/baseUrl=https://cdn.example.com
note

When accountKey is omitted, the Azure SDK's DefaultAzureCredential is used, which supports managed identities, environment variables, and other credential sources.

warning

Azure Blob Storage does not support per-object ACL changes. Calling updatePermission() on an AzureBlobStorageItem throws UnsupportedOperationException. Access control is managed at the container level via the disablePublicRead setting.

Google Cloud Storage

Stores files in Google Cloud Storage buckets.

Class: com.psddev.google.storage.GoogleCloudStorageItem

Artifact: com.brightspot.storage:gcp

SettingRequiredDescription
bucketNameYesName of the GCS bucket.
credentialsFileNoPath to a service account JSON credentials file. If omitted, uses Application Default Credentials.
predefinedAclNoThe PredefinedAcl to apply to uploaded objects. Defaults to PUBLIC_READ.
uniformBucketLevelAccessNoSet to true when the bucket uses uniform bucket-level access. Disables per-object ACL.

Example configuration:

1
dari/defaultStorage=gcs
2
dari/storage/gcs/class=com.psddev.google.storage.GoogleCloudStorageItem
3
dari/storage/gcs/bucketName=my-media-bucket
4
dari/storage/gcs/baseUrl=https://cdn.example.com
5
dari/storage/gcs/secureBaseUrl=https://cdn.example.com

Uniform bucket-level access

When uniformBucketLevelAccess is true, per-object ACLs are not set during upload. Access is controlled entirely by IAM policies on the bucket. This is the recommended approach for new GCS buckets.

Multi-CDN hashing

To distribute assets across multiple CDN domains, configure multiple base URLs and a hashing algorithm:

1
dari/storage/s3/baseUrls/1=https://cdn1.example.com
2
dari/storage/s3/baseUrls/2=https://cdn2.example.com
3
dari/storage/s3/baseUrls/3=https://cdn3.example.com
4
dari/storage/s3/hashAlgorithm=_pathHashCode

The built-in _pathHashCode algorithm distributes files across base URLs by hashing the file path. You can implement StorageItemHash to provide a custom hashing strategy. See Extending—Custom hashing for details.