Skip to main content

File & Image Storage

AdamRMS can keep uploaded images and files in one of two places, chosen with the File storage driver setting in the configuration menu:

  • Local - a folder on the AdamRMS server. Nothing else needs to be set up, which makes it the simplest choice for a self-hosted installation, but the folder needs to be kept (in Docker, on a volume) and backed up along with the database.
  • S3 - an AWS S3 Bucket, or a bucket from an S3-compatible service such as Backblaze, DigitalOcean Spaces, Cloudflare R2 or MinIO. Files are uploaded straight from users' browsers to the bucket, and downloaded from it, so they don't pass through the AdamRMS server.

Whichever you choose, set File storage enabled to Enabled to let users upload files.

AdamRMS remembers which driver holds each file, so changing the setting only affects files uploaded from then on - existing files keep working from where they are. To move them, see moving files between drivers.

Local storage​

Set the following in the configuration menu, or with the environment variables shown:

SettingEnvironment variableValue
File storage enabledCONFIG_FILES_ENABLEDEnabled
File storage driverCONFIG_FILES_STORAGE_DRIVERLocal
Local file storage folderCONFIG_FILES_LOCAL_PATHThe folder to keep files in. Defaults to storage in the AdamRMS folder, which is /var/www/html/storage in the Docker image

The folder must be writable by the web server, and should not be inside the web root (src): AdamRMS serves files itself, checking that the user may see each one. The links it hands out are signed and expire, in the same way as S3's, so a link to a private file can't be guessed or kept for later.

With Docker, mount a volume at /var/www/html/storage so that files are kept when the container is replaced:

services:
adamrms:
image: ghcr.io/adam-rms/adam-rms:latest
environment:
- CONFIG_FILES_ENABLED=Enabled
- CONFIG_FILES_STORAGE_DRIVER=Local
volumes:
- adamrms_files:/var/www/html/storage
volumes:
adamrms_files: {}

A named volume like this one is created writable by the container's web server. If you use a folder on the host instead (a bind mount, e.g. ./files:/var/www/html/storage), make sure it is writable by user id 33 (www-data).

Uploads pass through the web server, so they are limited by PHP's upload_max_filesize and post_max_size settings (64MB in the Docker image), and by any limit on request sizes in a proxy in front of AdamRMS.

Moving files between drivers​

bin/file-storage.php copies files from one driver to the other, and records the move so each file is then read from its new home. Run it on the AdamRMS server with the same environment variables as the web server - in Docker, with docker exec:

# How many files each driver holds
docker exec -it adamrms php bin/file-storage.php status

# List what would be moved, then move every file from S3 to local storage
docker exec -it adamrms php bin/file-storage.php migrate --to=Local --dry-run
docker exec -it adamrms php bin/file-storage.php migrate --to=Local

# Check every file is where AdamRMS expects it to be
docker exec -it adamrms php bin/file-storage.php verify

migrate leaves the original files where they were, so you can check everything works before removing them - or add --delete-source to delete each one once it has been copied. It can be stopped and run again at any time, and --limit=100 moves files in batches. Once files are moved, change the File storage driver setting so that new uploads go to the same place.

When AdamRMS is configured for both S3 and local storage, files can be moved either way (--to=S3 moves local files into the bucket).

Removing deleted files​

When a file is deleted in AdamRMS it is hidden straight away, but kept so it could be restored. To permanently remove locally stored files that were deleted more than 30 days ago, run:

docker exec -it adamrms php bin/file-storage.php purge

--days=90 changes how long deleted files are kept, and --dry-run lists the files that would be removed without removing them. You may want to run this on a schedule, e.g. weekly with cron. For S3, use your bucket's lifecycle rules instead.

S3 storage​

To set up S3 file storage, set the following settings in the configuration menu:

File Storage​

File storage enabled Whether file storage is enabled or disabled. If disabled, AdamRMS will not allow users to upload files.

File storage driver​

Set to S3, the default.

AWS Server Key​

The AWS server key.

AWS Server Secret Key​

The AWS server secret key.

AWS S3 Bucket Name​

The AWS S3 bucket name.

AWS S3 Bucket Browser Endpoint​

The AWS S3 bucket endpoint, which must be accessible over the internet for user browsers to upload files

https://s3.eu-west-1.amazonaws.com is the default for the eu-west-1 region.

AWS S3 Bucket Server Endpoint​

The AWS S3 bucket endpoint for the server to use to upload files, and to read files it needs itself (such as logos for generated PDFs) - this is almost certainly the same as the above, except in some very specific circumstances such as running in docker containers, where the server may need to reach MinIO by its container name.

https://s3.eu-west-1.amazonaws.com is the default for the eu-west-1 region.

Should path-style requests be sent to the upload endpoint?​

This should be disabled for almost all providers

AWS S3 Bucket Region​

The AWS S3 bucket region.

e.g. eu-west-1

AWS CloudFront Enabled​

Whether AWS CloudFront is enabled.

AWS CloudFront Private Key​

The AWS CloudFront private key.

AWS CloudFront Key Pair ID​

The AWS CloudFront key pair ID.

AWS S3 CDN Endpoint​

The AWS S3 CDN endpoint. This is the URL that users will access the files from: it may be cloudfront, or it may be s3/an alternative.

Cloudflare Image Transformation Domain​

An optional domain for Cloudflare Image Transformations. When set, image file URLs (jpg, jpeg, png, gif, webp, avif, svg, bmp, tiff, tif, ico) will be routed through Cloudflare's image transformation pipeline, which can optimise and cache images automatically.

The value should be just the domain, e.g. https://cdn.yourdomain.com (without a trailing slash). The application automatically appends the /cdn-cgi/image/onerror=redirect path. The resulting image URL will be:

https://cdn.yourdomain.com/cdn-cgi/image/onerror=redirect/<ORIGINAL_URL>

Where <ORIGINAL_URL> is the S3 pre-signed URL or CloudFront signed URL (depending on your configuration), appended as a plain absolute URL (not URL-encoded) as required by Cloudflare's URL format.

When a size hint is provided by the application (e.g. tiny, small, medium, or large), Cloudflare resizing options are appended to the URL automatically:

SizeCloudflare options
tinywidth=50,fit=scale-down
smallwidth=100,fit=scale-down
mediumwidth=500,fit=scale-down
largewidth=1000,fit=scale-down

For example, a small image would produce:

https://cdn.yourdomain.com/cdn-cgi/image/onerror=redirect,width=100,fit=scale-down/<ORIGINAL_URL>

Non-image files are not affected and will continue to be served directly from S3 or CloudFront.

Setting up a bucket​

BackBlaze B2​

BackBlaze is a cloud storage service which provides S3-compatible object storage.

Bucket Info​

Set the bucket info to:

{"cache-control":"public, max-age=900, s-maxage=3600, stale-while-revalidate=900, stale-if-error=3600"}
Bucket CORS​

You need to setup the CORS on the bucket to allow uploads

  1. Download and authenticate the AWS Cli (using your Backblaze credentials).
  2. Create a file called cors.json file, and add the following the information:
{
"CORSRules": [
{
"AllowedHeaders": ["*"],
"AllowedMethods": ["POST", "PUT", "GET", "HEAD"],
"AllowedOrigins": ["*"],
"ExposeHeaders": [
"etag",
"x-bz-content-sha1",
"x-amz-meta-qqfilename",
"x-amz-meta-size",
"x-amz-meta-subtype",
"x-amz-meta-typeid",
"authorization",
"content-type",
"origin",
"x-amz-acl",
"x-amz-content-sha256",
"x-amz-date",
"range",
"Access-Control-Allow-Origin"
],
"MaxAgeSeconds": 86400
}
]
}
  1. Run the following command to apply the policy to your new bucket:
aws s3api put-bucket-cors --bucket=<BUCKETNAME> --endpoint-url=https://s3.eu-central-003.backblazeb2.com --cors-configuration=file://backblaze-cors.json

The region is usually eu-central-003 for setting in configuration menu of AdamRMS

CDN Url is https://s3.eu-central-003.backblazeb2.com/<BUCKETNAME>

And endpoint is s3.eu-central-003.backblazeb2.com

AWS S3​

To use AWS S3 you need to create an IAM user

File S3 Bucket​

Create an S3 Bucket, with the follwing Policy

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": ["s3:PutObject", "s3:GetObject"],
"Resource": "arn:aws:s3:::<BUCKETNAME>/*"
}
]
}
  • Then set the following environment variables, with information from the S3 console.
Cloudfront​

Using cloudfront is optional, but will improve image and file download times.

Also note that when setting up a policy for the Cloudfront distribution, you must enable:

  • Query strings - Include specified query strings response-content-disposition