# CDN for Media

The Media module in Orchard Core manages media files stored in the `Media` folder. By default, media files are served directly from our CMS. However, when a **CDN Base URL** is configured, Orchard Core replaces the default URL with the CDN URL in the generated media links.

For example:

* Default URL: `http://localhost:5022/media/example.jpg`
* CDN URL: `https://ocbc-cdn-demo.com/media/example.jpg`

We can configure the `CdnBaseUrl` dynamically in our `Program.cs` of our core CMS project as demonstrated below.

```csharp
services.PostConfigure<MediaOptions>(o => {
    // ...
    
    o.CdnBaseUrl = "https://ocbc-cdn-demo.com";
});
```

To verify that the setting has been applied, we can visit the Administration UI to get the Media CDN URL, as shown in the following screenshot.

<figure><img src="https://1652590091-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FSUPKDOneQELR7Te0EliF%2Fuploads%2Fv2bnSwk16JVmmsKblpRq%2Fimage.png?alt=media&#x26;token=b6a23545-994d-4694-a17c-fcce52136973" alt=""><figcaption><p>The Media CDN base URL will be shown here if it is correctly configured.</p></figcaption></figure>

Orchard Core provides the `IMediaFileStore` service to manage media files and generate URLs programmatically. For example:

```csharp
// ...
using OrchardCore.Media;

namespace OCBC.HeadlessCMS.Controllers;

[ApiController]
[Route("api/v1/product")]
public class ProductController(
    // ...
    IMediaFileStore mediaFileStore) : Controller
{
    [HttpGet("get-media-cdn")]
    public async Task<IActionResult> GetMediaCdn()
    {
        return Ok(mediaFileStore.MapPathToPublicUrl("/15-autumn-in-japan-body.jpg"));
    }
}
```

The demo endpoint above will return the value "`https://ocbc-cdn-demo.com/media/15-autumn-in-japan-body.jpg`".


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://gcl.gitbook.io/orchard-core-basics-companion-ocbc/aws-integration/cdn-for-media.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
