Orchard Core Amazon S3 Media Storage
Module Overview
The OrchardCore.Media.AmazonS3 module stores media in S3 buckets instead of
App_Data:
OrchardCore.Media.AmazonS3— replaces the media store with S3. Depends on (and enables)OrchardCore.Media.Cache.OrchardCore.Media.AmazonS3.ImageCache— stores resized images in S3 instead ofwwwroot/{tenant}/media-cache.
Media is still served by the Orchard Core site: the Media Cache fetches objects
on demand, which keeps on-the-fly resizing working. Only one storage provider
is active at a time. Invalid configuration logs an error and falls back to local
file storage.
{
"steps": [
{
"name": "Feature",
"enable": [
"OrchardCore.Media.AmazonS3",
"OrchardCore.Media.AmazonS3.ImageCache"
],
"disable": []
}
]
}
Amazon S3 Media Storage (`OrchardCore:Media:AmazonS3`)
| Property | Description | Default |
|---|---|---|
| BucketName | Bucket name (required). Templatable. | |
| Region | Region endpoint, e.g. eu-central-1. Region or ServiceURL is required. | |
| ServiceURL | Custom endpoint (emulators, S3-compatible stores). Use instead of Region. | |
| ForcePathStyle | Path-style addressing (http://host/bucket), required by emulators. | false |
| Profile, ProfilesLocation | AWS CLI profile and custom profiles file. | |
| Credentials:AccessKey, Credentials:SecretKey | Explicit keys when hosted outside AWS. | |
| BasePath | Sub-path inside the bucket, e.g. /media. Templatable. | "" |
| CreateBucket | Create the bucket on startup (without ACLs). | false |
| RemoveBucket | Delete the bucket when the tenant is removed. | false |
Hosted in AWS (EC2, ECS, EKS), BucketName is enough; credentials come from the
IAM role:
{
"OrchardCore": {
"Media": {
"AmazonS3": {
"BucketName": "my-orchard-media",
"Region": "eu-central-1",
"BasePath": "/media"
}
}
}
}
Hosted outside AWS, prefer a profile or environment variables over keys in
appsettings.json:
{
"OrchardCore": {
"Media": {
"AmazonS3": {
"BucketName": "my-orchard-media",
"Region": "eu-central-1",
"Profile": "default",
"BasePath": "/media",
"CreateBucket": true
}
}
}
}
Environment variables: OrchardCore__Media__AmazonS3__BucketName,
OrchardCore__Media__AmazonS3__Credentials__AccessKey,
OrchardCore__Media__AmazonS3__Credentials__SecretKey.
AWS Credentials Loading Order
OrchardCore:Media:AmazonS3 is a subset of AWSOptions and resolves credentials
in this order:
- The
Credentialssection. - Shared credentials file at
ProfilesLocation(profile and location set). - SDK Store (Windows only) when only the profile is set.
- Shared credentials file in the default location when only the profile is set.
- Web Identity Federation (OIDC token file from environment variables).
CredentialsProfileStoreChain(SDK Store, then default shared file).- Environment variables
AWS_ACCESS_KEY_IDandAWS_SECRET_ACCESS_KEY. - ECS task or EC2 instance credentials (IAM roles).
Bucket Access
- Buckets created with
CreateBucket: truehave ACLs disabled. - Private bucket (recommended): media is served through Orchard Core, so only the application identity needs access.
- Public bucket: only when clients or a CDN read S3 directly. Add an explicit read policy and make sure Block Public Access does not cancel it.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AddPerm",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::YOUR-BUCKET-NAME/YOUR-BASE-PATH/*"
}
]
}
Tenant Templating
BucketName and BasePath accept Liquid with ShellSettings in scope.
{{ ShellSettings.Name }} is lowercased; the full name must follow S3 bucket
naming rules. Only default Liquid filters and tags are available.
{
"OrchardCore": {
"Media": {
"AmazonS3": {
"BucketName": "{{ ShellSettings.Name }}-media",
"Region": "eu-central-1",
"BasePath": "/media"
}
}
}
}
Single bucket with a folder per tenant:
{
"OrchardCore": {
"Media": {
"AmazonS3": {
"BucketName": "shared-media",
"Region": "eu-central-1",
"BasePath": "{{ ShellSettings.Name }}/Media"
}
}
}
}
Local S3 Emulator
Use ServiceURL (no Region), ForcePathStyle: true, and dummy credentials:
{
"OrchardCore": {
"Media": {
"AmazonS3": {
"ServiceURL": "http://localhost:9444/",
"Profile": "default",
"Credentials": {
"SecretKey": "dummy",
"AccessKey": "dummy"
},
"BasePath": "/media",
"CreateBucket": true,
"RemoveBucket": true,
"BucketName": "media",
"ForcePathStyle": true
}
}
}
}
# S3Mock (Adobe)
docker run -p 9444:9090 -t adobe/s3mock:latest
# LocalS3 (Robothy)
docker run -d -e MODE=IN_MEMORY -p 9444:80 luofuxiang/local-s3:latest
Media Cache
- Enabled automatically with S3 storage; local remote-media files live in
wwwroot/{tenant}/ms-cache. - Settings → Media → Cache (permission
MediaPermissions.ManageAssetCache) offers a Purge action. - With a CDN, purge only after it has fetched most assets. Each PoP caches independently and CDNs evict on their own schedule, so the bucket must always stay reachable for re-fetches.
Amazon S3 Image Cache (`OrchardCore:Media:AmazonS3:ImageCache`)
Stores resized images in S3 (AWSS3ResizedImageCache, options
AwsMediaImageCacheOptions). Depends on OrchardCore.Media.AmazonS3.
BucketName and BasePath can be templated like the storage section.
{
"OrchardCore": {
"Media": {
"AmazonS3": {
"ImageCache": {
"BucketName": "media-image-cache",
"BasePath": "/cache",
"CreateBucket": true,
"RemoveBucket": false
}
}
}
}
}
- Environment variable:
OrchardCore__Media__AmazonS3__ImageCache__BucketName. BucketName,BasePath,CreateBucketandRemoveBucketcome from theImageCachesection;Credentialstoo, falling back to theMedia:AmazonS3credentials when theImageCachesection doesn't define them. The SDK settings (Region,ServiceURL,Profile,ForcePathStyle) are bound fromMedia:AmazonS3, so keep the cache bucket in the same region/endpoint as the media bucket. The image cache can be active without the media store, which only becomes active once its ownBucketNameis set.- Useful with ephemeral containers and slow local disks.
- Cache files are only removed with the tenant when each tenant has its own bucket.
Resumable Uploads
When OrchardCore.Media.Tus is also enabled, TUS partial uploads are buffered
with S3 multipart uploads (S3TusTempStore) under a _tus-uploads prefix, so
any instance can continue an upload. Without a valid S3 configuration, TUS keeps
using the local temp directory. See orchardcore-media-gallery for TUS,
SignalR and multi-instance guidance.
Upgrading from 3.x
- Rename
OrchardCore_Media_AmazonS3toMedia:AmazonS3andOrchardCore_Media_AmazonS3_ImageSharp_CachetoMedia:AmazonS3:ImageCache, including env vars (OrchardCore__OrchardCore_Media_AmazonS3__BucketName→OrchardCore__Media__AmazonS3__BucketName). The old names are deprecated but still read; the new name wins when both exist. - Use the feature ID
OrchardCore.Media.AmazonS3.ImageCachein recipes. The obsoleteOrchardCore.Media.AmazonS3.ImageSharpImageCacheID only enables the new feature. AwsImageSharpImageCacheOptionsis nowAwsMediaImageCacheOptions, and resizing uses the built-in NetVips pipeline (no ImageSharp.Web).- A malformed value in
Media:AmazonS3no longer prevents the tenant from starting: a critical error is logged and the tenant keeps using local file storage. If files stored on S3 aren't served after upgrading, check the logs. AwsStorageOptionsExtensionis nowinternal: itsBindConfigurationandValidatemethods (nowTryBindConfiguration) can't be called outside the Amazon S3 module. Configure the module through theMedia:AmazonS3andMedia:AmazonS3:ImageCachesections: the module's startups bind and validate them, and only replace the local storage when they are valid. The Redis (RedisOptionsExtension) and Azure SignalR option binders are internal too.