Media Upload
December 23, 2024 ยท View on GitHub
The blog supports uploading media assets (images, etc.) directly to Azure Blob Storage while writing blog posts.
Configuration
The following settings in appsettings.json control media upload functionality:
{
"ImageStorageProvider": "Azure",
"ImageStorage": {
"AuthenticationMode": "Default",
"ConnectionString": "",
"ServiceUrl": "",
"ContainerName": ""
}
}
| Property | Type | Description |
|---|---|---|
| ImageStorageProvider | string | Currently only supports Azure for Azure Blob Storage. |
| AuthenticationMode | string | Authentication method - either Default for Microsoft Entra ID or ConnectionString for connection string auth |
| ConnectionString | string | Azure Storage connection string (only used and mandatory when AuthenticationMode is ConnectionString) |
| ServiceUrl | string | Azure Blob Storage service URL (only used and mandatory when AuthenticationMode is Default) |
| ContainerName | string | Name of the Azure Storage container to store uploaded files. It can be nested containers as well path/to/upload |
| CdnEndpoint | string | Optional CDN endpoint to use for uploaded images. If set, the blog will return this URL instead of the storage account URL for uploaded assets. |
Authentication Methods
Default Authentication
Uses Microsoft Entra ID (formerly Azure AD) managed identity or default credentials. This requires:
- Setting up proper RBAC permissions in Azure
- Configuring the ServiceUrl to point to your storage account
- No sensitive credentials needed in config
Connection String Authentication
Uses a storage account connection string for authentication:
- Get connection string from Azure Portal
- Add it to the ConnectionString setting
- No additional Azure setup required
Usage
- Start writing a blog post in the markdown editor
- Drag & drop images onto the editor
- A dialog appears asking for:
- File name (can include subdirectories)
- Whether to enable browser caching via
Cache-Controlheaders (currently set to one week)
- The image gets uploaded and a markdown image link is inserted
Performance Note
Use a CDN endpoint for uploaded images to improve performance. This can be set in the CdnEndpoint setting. Azure CDN has integrated support for HTTP/2 and bring other performance benefits.