Orchardcore media gallery

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore media gallery is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for the Orchard Core 4 Vue 3 Media Gallery and the api/media Media API. Covers gallery features, list and grid views, DisableThumbnails, upload size and extension limits in pickers, MediaApiSettings AuthenticationScheme Cookie or Bearer, antiforgery, the MediaApiPkce, MediaApiStandalone and Me

How to use this skill

Skill file

Orchard Core Media Gallery and Media API

Orchard Core 4.0 rewrote the Media Library admin UI as a Vue 3 Media Gallery

backed by the Media API, minimal-API endpoints under api/media. The same

gallery powers the Media Library page, the media picker modal (media fields,

HTML/Markdown editors) and the media field gallery editor. For media storage,

profiles, permissions and image resizing see orchardcore-media.

Features

| Feature ID | Purpose |

|---|---|

| OrchardCore.Media | Gallery, Media API, picker. Always required. |

| OrchardCore.Media.Tus | Resumable chunked uploads through the TUS protocol (/api/media/tus). |

| OrchardCore.Media.SignalR | Real-time updates on the /hubs/media hub. Depends on OrchardCore.SignalR. |

| OrchardCore.SignalR | Shared SignalR hosting, the signalr client resource and the SignalR policy. |

| OrchardCore.SignalR.Redis | Redis backplane. Depends on OrchardCore.Redis. |

| OrchardCore.SignalR.Azure | Azure SignalR Service backplane. |

{
  "steps": [
    {
      "name": "Feature",
      "enable": [
        "OrchardCore.Media",
        "OrchardCore.Media.Tus",
        "OrchardCore.Media.SignalR"
      ],
      "disable": []
    }
  ]
}

Gallery Behavior

Disable thumbnails

Force the list view everywhere (Media Library, media picker modal, media field

gallery editor) and hide the grid toggle and thumbnail size setting:

{
  "OrchardCore": {
    "Media": {
      "DisableThumbnails": true
    }
  }
}

Upload limits

Media API Authentication

The Media API, the TUS endpoint and the media hub authenticate with exactly one

scheme, chosen in Settings → Media → API

(MediaApiSettings.AuthenticationScheme, permission ManageMediaApiSettings,

granted to Administrators). Changing it releases the shell so the MediaApi

policy is rebuilt.

| Scheme | Behavior |

|---|---|

| Cookie (default) | Same-origin admin cookie. Mutating requests must carry the antiforgery token (RequestVerificationToken header or __RequestVerificationToken form field); failures return 400 Problem Details. Works out of the box. |

| Bearer | Only Bearer tokens on the Api scheme. The gallery silently gets an OAuth2 authorization-code + PKCE token (hidden iframe, prompt=none) from the tenant's OpenID server, renews it, and sends it to API calls, Uppy/TUS uploads and SignalR. A 401 is retried once after renewal. Requires OrchardCore.OpenId.Validation. |

The media hub accepts both the application cookie and Api bearer tokens in

either mode.

Provision Bearer mode

Run the Media API — Bearer/PKCE recipe (MediaApiPkce) from

Tools → Recipes. It enables OrchardCore.OpenId.Management,

OrchardCore.OpenId.Server and OrchardCore.OpenId.Validation, sets

MediaApiSettings.AuthenticationScheme to Bearer, enables the

authorization-code flow with PKCE required, sets local token validation

(Tenant: "Default"), and registers the public media_gallery client. Before

running it, replace https://localhost:5001 with the tenant origin (keep the

/OrchardCore.Media/media-gallery-oidc-silent.html path, including any tenant

prefix), use the right tenant name, and make sure gallery users have roles

granting media permissions (the roles scope carries them into the token).

Switch only the scheme in your own recipe:

{
  "steps": [
    {
      "name": "Settings",
      "MediaApiSettings": {
        "AuthenticationScheme": "Bearer"
      }
    }
  ]
}

Standalone gallery app

The gallery SPA can run on its own origin. The first sign-in is an interactive

redirect; renewal stays silent.

{
  "orchardBaseUrl": "https://cms.example.com/",
  "appBaseUrl": "https://media.example.com/",
  "oidcClientId": "media_gallery",
  "oidcScope": "openid email profile roles",
  "signalrEnabled": false,
  "maxFileSize": 30000000
}

Keep maxFileSize equal to the tenant's Media:MaxFileSize. Set

signalrEnabled to true only once CORS covers /hubs/media.

Media API Endpoints

All endpoints require the MediaApi policy except localizations, and then

check MediaPermissions (ManageMedia, folder-scoped ManageMediaFolder,

UploadRestrictedMedia) in the handler. Errors are RFC 9457 Problem Details.

Simple parameters are query string values.

| Method and route | Parameters | Returns |

|---|---|---|

| GET api/media/GetDirectoryTree | none | Folder tree (DirectoryTreeNodeDto) |

| GET api/media/GetFolders | path, skip, take | PaginatedFoldersDto (Items, HasMore) |

| GET api/media/GetDirectoryContent | path, extensions | DirectoryContentDto (Folders, Files) |

| GET api/media/GetMediaItems | path, extensions | Files of a folder |

| GET api/media/GetAllMediaItems | extensions | Every file |

| GET api/media/GetMediaItem | path | One FileStoreEntryDto |

| GET api/media/GetMediaFieldItems | paths (repeated) | Items selected in a media field |

| GET api/media/GetPermittedStorage | none | PermittedStorageDto (Bytes, Text) |

| GET api/media/localizations | none | Gallery strings (anonymous) |

| POST api/media/Upload | path, extensions, multipart files | UploadFilesResultDto (per-file Error) |

| POST api/media/CreateFolder | path, name | Created folder |

| POST api/media/DeleteFolder | path | 200 |

| POST api/media/DeleteMedia | path | 200 |

| POST api/media/DeleteMediaList | JSON body, array of paths | 200 |

| POST api/media/MoveMedia | oldPath, newPath (rename or move) | 200 |

| POST api/media/MoveMediaList | JSON body { mediaNames, sourceFolder, targetFolder } | 200 |

| POST api/media/CopyMedia | oldPath, newPath | Copied file |

| GET api/media/TusFileInfo/{uploadId} | TUS only | Upload info |

| /api/media/tus | TUS protocol | Resumable upload endpoint (TUS only) |

POST api/media/Upload reads the destination folder from the path query

parameter, then from the path multipart form field; send ?path= or omit

both to upload to the library root (Attached media field uploads go to their

temporary folder since this fix, not to the root).

MoveMedia, CopyMedia and uploads re-check the target extension against the

user's effective extension list. See references/media-api-examples.md for

calls from JavaScript and C#.

TUS Resumable Uploads (`OrchardCore.Media.Tus`)

Replace the store in your own module:

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using OrchardCore.Media.Services;
using OrchardCore.Modules;

[RequireFeatures("OrchardCore.Media.Tus")]
public sealed class TusStoreStartup : StartupBase
{
    public override void ConfigureServices(IServiceCollection services)
    {
        services.Replace(ServiceDescriptor.Singleton<ITusTempStore, MyTusTempStore>());
    }
}

ITusTempStore members: CreateFileAsync, AppendDataAsync (stream and

PipeReader overloads, returning bytes written), DeleteFileAsync,

FileExistAsync, OpenReadStream, GetFileLength.

SignalR Real-time Updates (`OrchardCore.Media.SignalR`)

{
  "OrchardCore": {
    "Redis": {
      "Configuration": "your-redis-host:6379,password=...,ssl=true"
    },
    "SignalR": {
      "Azure": {
        "ConnectionString": "Endpoint=https://<service>.service.signalr.net;AccessKey=...;Version=1.0;",
        "ApplicationName": "OrchardCore"
      }
    }
  }
}

Multi-instance Deployment

| Component | Configure |

|---|---|

| SignalR backplane | OrchardCore.SignalR.Redis or OrchardCore.SignalR.Azure |

| TUS chunks | Shared OrchardCore:TempDirectory:Path (NFS, Azure Files, EFS), Azure/S3 media storage (ITusTempStore), or sticky sessions |

| TUS metadata and locks | OrchardCore.Redis.Cache and OrchardCore.Redis.Lock |

| Media files | Azure Blob, Amazon S3, or a shared filesystem (orchardcore-azure-media, orchardcore-amazon-s3-media) |

| Data Protection keys | OrchardCore.Redis.DataProtection or OrchardCore.DataProtection.Azure |

Sharing the Data Protection key ring is mandatory once you scale out: the admin

cookie, antiforgery tokens and the OpenID access tokens (Data Protection

format) are all encrypted with it, and per-instance keys surface as random

401 errors in the gallery. Sticky sessions keep TUS chunks on one instance

but lose the upload if that instance stops. Non-TUS uploads use one request per

file and are unaffected.

A single Redis instance can cover the backplane, keys, cache and locks:

{
  "steps": [
    {
      "name": "Feature",
      "enable": [
        "OrchardCore.Redis",
        "OrchardCore.Redis.Cache",
        "OrchardCore.Redis.Lock",
        "OrchardCore.Redis.DataProtection",
        "OrchardCore.SignalR.Redis",
        "OrchardCore.Media.SignalR",
        "OrchardCore.Media.Tus"
      ],
      "disable": []
    }
  ]
}

Upgrading from 3.x

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.