# Orchardcore Media

> Skill for managing media in Orchard Core. Covers media library configuration, media profiles, ImageSharp processing, media field usage, storage providers, image caches, and media storage events. Use this skill when requests mention Orchard Core Media, Configure Media Management, Enabling Media Features, Media Settings Configuration, Media Profiles via Recipe, or closely related Orchard Core implementation, setup, extension, or troubleshooting work. Strong matches include OrchardCore.Media, OrchardCore.Media.Indexing, OrchardCore.Media.Cache, IMediaEventHandler, MediaPermittedStorageContext, MediaField, IMediaCreatingEventHandler, MediaCreatingContext, AlterPartDefinition, ArticlePart, WithField.

- Skill: `crestapps/orchardcore-media` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add crestapps/orchardcore-media`
- Raw SKILL.md: https://api.skillmd.com/api/skills/crestapps/orchardcore-media/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- License: Apache-2.0
- Author: CrestApps (https://skillmd.com/u/crestapps)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/crestapps/orchardcore-media

---


# Orchard Core Media - Prompt Templates

## Configure Media Management

You are an Orchard Core expert. Generate configuration and code for managing media in Orchard Core.

### Guidelines

- Enable `OrchardCore.Media` to use the media library.
- Media files are stored under `/media/` by default using the file system.
- Azure Blob Storage and Amazon S3 can be configured as alternative storage providers.
- Media profiles define image processing pipelines (resize, crop, format conversion).
- Use `MediaField` on content types to allow users to attach media files.
- Media processing uses ImageSharp through ImageSharp.Web.
- Configure allowed file extensions and max file size in media settings.
- Use media tokens in Liquid templates to generate processed image URLs.

### Image Processing

Image processing uses ImageSharp.Web. Media profiles can resize, crop, and
convert image formats through the configured ImageSharp pipeline.

The default resized-image cache is stored under
`wwwroot/{tenant}/is-cache`.

### Enabling Media Features

```json
{
  "steps": [
    {
      "name": "Feature",
      "enable": [
        "OrchardCore.Media",
        "OrchardCore.Media.Indexing",
        "OrchardCore.Media.Cache"
      ],
      "disable": []
    }
  ]
}
```

### Media Settings Configuration

```json
{
  "OrchardCore": {
    "OrchardCore_Media": {
      "MaxFileSize": 104857600,
      "AllowedFileExtensions": [
        ".jpg", ".jpeg", ".png", ".gif", ".webp",
        ".svg", ".pdf", ".doc", ".docx", ".mp4"
      ],
      "CdnBaseUrl": "https://cdn.example.com"
    }
  }
}
```

### Azure Blob Storage Configuration

```json
{
  "OrchardCore": {
    "OrchardCore_Media_Azure": {
      "ConnectionString": "{{AzureConnectionString}}",
      "ContainerName": "media",
      "BasePath": "{{TenantName}}"
    }
  }
}
```

### Media Profiles via Recipe

```json
{
  "steps": [
    {
      "name": "MediaProfiles",
      "MediaProfiles": {
        "{{ProfileName}}": {
          "Hint": "{{Description}}",
          "Width": 800,
          "Height": 600,
          "Mode": "Crop",
          "Format": "webp",
          "Quality": 80
        }
      }
    }
  ]
}
```

Processing modes include:
- `Crop` - Crops the image to the exact dimensions.
- `Pad` - Pads the image to fit dimensions.
- `BoxPad` - Pads the image within a box.
- `Max` - Resizes to fit within max dimensions while preserving aspect ratio.
- `Min` - Resizes to fit minimum dimensions.
- `Stretch` - Stretches the image to exact dimensions.

### Using Media in Liquid Templates

```liquid
<!-- Display an image with a media profile -->
<img src="{{ Model.ContentItem.Content.MyPart.Image.Paths[0] | asset_url | append: '?width=400&height=300&rmode=crop' }}" />

<!-- Using a named media profile -->
<img src="{{ Model.ContentItem.Content.MyPart.Image.Paths[0] | asset_url | append: '?profile=thumbnail' }}" />

<!-- Responsive images -->
<img src="{{ Model.ContentItem.Content.MyPart.Image.Paths[0] | asset_url | append: '?width=800' }}"
     srcset="{{ Model.ContentItem.Content.MyPart.Image.Paths[0] | asset_url | append: '?width=400' }} 400w,
             {{ Model.ContentItem.Content.MyPart.Image.Paths[0] | asset_url | append: '?width=800' }} 800w,
             {{ Model.ContentItem.Content.MyPart.Image.Paths[0] | asset_url | append: '?width=1200' }} 1200w" />
```

### Custom Media Processing

```csharp
using OrchardCore.Media.Events;

public sealed class CustomMediaResizingFilter : IMediaCreatingEventHandler
{
    public Task<Stream> MediaCreatingAsync(MediaCreatingContext context, Stream creatingStream)
    {
        return Task.FromResult(creatingStream);
    }
}
```

### Restrict Permitted Media Storage

Use `IMediaEventHandler.MediaPermittedStorageAsync` to apply a storage limit
for custom stores or quotas. Call `Constrain` so multiple handlers can safely
apply the smallest limit:

```csharp
using OrchardCore.Media.Events;

public sealed class MediaQuotaEventHandler : IMediaEventHandler
{
    public Task MediaPermittedStorageAsync(MediaPermittedStorageContext context)
    {
        context.Constrain(10 * 1024 * 1024);
        return Task.CompletedTask;
    }
}
```

### Attaching Media Field to Content Type

```csharp
_contentDefinitionManager.AlterPartDefinition("ArticlePart", part => part
    .WithField("FeaturedImage", field => field
        .OfType("MediaField")
        .WithDisplayName("Featured Image")
        .WithSettings(new MediaFieldSettings
        {
            Multiple = false,
            AllowMediaText = true,
            AllowAnchors = true
        })
    )
);
```

