Table of Contents

Class MediaController

Namespace
Umbraco.Cms.Web.BackOffice.Controllers
Assembly
Umbraco.Web.BackOffice.dll
[Authorize(Policy = "SectionAccessMedia")]
public class MediaController : ContentControllerBase
Inheritance
MediaController
Inherited Members

Remarks

This controller is decorated with the UmbracoApplicationAuthorizeAttribute which means that any user requesting access to ALL of the methods on this controller will need access to the media application.

Constructors

MediaController(ICultureDictionary, ILoggerFactory, IShortStringHelper, IEventMessagesFactory, ILocalizedTextService, IOptionsSnapshot<ContentSettings>, IMediaTypeService, IMediaService, IEntityService, IBackOfficeSecurityAccessor, IUmbracoMapper, IDataTypeService, ISqlContext, IContentTypeBaseServiceProvider, IRelationService, PropertyEditorCollection, MediaFileManager, MediaUrlGeneratorCollection, IHostingEnvironment, IImageUrlGenerator, IJsonSerializer, IAuthorizationService, AppCaches)

[Obsolete("Use constructor overload that has fileStreamSecurityValidator, scheduled for removal in v14")]
public MediaController(ICultureDictionary cultureDictionary, ILoggerFactory loggerFactory, IShortStringHelper shortStringHelper, IEventMessagesFactory eventMessages, ILocalizedTextService localizedTextService, IOptionsSnapshot<ContentSettings> contentSettings, IMediaTypeService mediaTypeService, IMediaService mediaService, IEntityService entityService, IBackOfficeSecurityAccessor backofficeSecurityAccessor, IUmbracoMapper umbracoMapper, IDataTypeService dataTypeService, ISqlContext sqlContext, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IRelationService relationService, PropertyEditorCollection propertyEditors, MediaFileManager mediaFileManager, MediaUrlGeneratorCollection mediaUrlGenerators, IHostingEnvironment hostingEnvironment, IImageUrlGenerator imageUrlGenerator, IJsonSerializer serializer, IAuthorizationService authorizationService, AppCaches appCaches)

Parameters

cultureDictionary ICultureDictionary
loggerFactory ILoggerFactory
shortStringHelper IShortStringHelper
eventMessages IEventMessagesFactory
localizedTextService ILocalizedTextService
contentSettings IOptionsSnapshot<ContentSettings>
mediaTypeService IMediaTypeService
mediaService IMediaService
entityService IEntityService
backofficeSecurityAccessor IBackOfficeSecurityAccessor
umbracoMapper IUmbracoMapper
dataTypeService IDataTypeService
sqlContext ISqlContext
contentTypeBaseServiceProvider IContentTypeBaseServiceProvider
relationService IRelationService
propertyEditors PropertyEditorCollection
mediaFileManager MediaFileManager
mediaUrlGenerators MediaUrlGeneratorCollection
hostingEnvironment IHostingEnvironment
imageUrlGenerator IImageUrlGenerator
serializer IJsonSerializer
authorizationService IAuthorizationService
appCaches AppCaches

MediaController(ICultureDictionary, ILoggerFactory, IShortStringHelper, IEventMessagesFactory, ILocalizedTextService, IOptionsSnapshot<ContentSettings>, IMediaTypeService, IMediaService, IEntityService, IBackOfficeSecurityAccessor, IUmbracoMapper, IDataTypeService, ISqlContext, IContentTypeBaseServiceProvider, IRelationService, PropertyEditorCollection, MediaFileManager, MediaUrlGeneratorCollection, IHostingEnvironment, IImageUrlGenerator, IJsonSerializer, IAuthorizationService, AppCaches, IFileStreamSecurityValidator)

[ActivatorUtilitiesConstructor]
public MediaController(ICultureDictionary cultureDictionary, ILoggerFactory loggerFactory, IShortStringHelper shortStringHelper, IEventMessagesFactory eventMessages, ILocalizedTextService localizedTextService, IOptionsSnapshot<ContentSettings> contentSettings, IMediaTypeService mediaTypeService, IMediaService mediaService, IEntityService entityService, IBackOfficeSecurityAccessor backofficeSecurityAccessor, IUmbracoMapper umbracoMapper, IDataTypeService dataTypeService, ISqlContext sqlContext, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IRelationService relationService, PropertyEditorCollection propertyEditors, MediaFileManager mediaFileManager, MediaUrlGeneratorCollection mediaUrlGenerators, IHostingEnvironment hostingEnvironment, IImageUrlGenerator imageUrlGenerator, IJsonSerializer serializer, IAuthorizationService authorizationService, AppCaches appCaches, IFileStreamSecurityValidator streamSecurityValidator)

Parameters

cultureDictionary ICultureDictionary
loggerFactory ILoggerFactory
shortStringHelper IShortStringHelper
eventMessages IEventMessagesFactory
localizedTextService ILocalizedTextService
contentSettings IOptionsSnapshot<ContentSettings>
mediaTypeService IMediaTypeService
mediaService IMediaService
entityService IEntityService
backofficeSecurityAccessor IBackOfficeSecurityAccessor
umbracoMapper IUmbracoMapper
dataTypeService IDataTypeService
sqlContext ISqlContext
contentTypeBaseServiceProvider IContentTypeBaseServiceProvider
relationService IRelationService
propertyEditors PropertyEditorCollection
mediaFileManager MediaFileManager
mediaUrlGenerators MediaUrlGeneratorCollection
hostingEnvironment IHostingEnvironment
imageUrlGenerator IImageUrlGenerator
serializer IJsonSerializer
authorizationService IAuthorizationService
appCaches AppCaches
streamSecurityValidator IFileStreamSecurityValidator

Properties

UserStartNodes

protected int[] UserStartNodes { get; }

Property Value

int[]

Methods

DeleteById(int)

Moves an item to the recycle bin, if it is already there then it will permanently delete it

[Authorize(Policy = "MediaPermissionPathById")]
[HttpPost]
public IActionResult DeleteById(int id)

Parameters

id int

Returns

IActionResult

EmptyRecycleBin()

Empties the recycle bin

[HttpDelete]
[HttpPost]
public IActionResult EmptyRecycleBin()

Returns

IActionResult

GetById(Guid)

Gets the media item by id

[Authorize(Policy = "MediaPermissionPathById")]
public MediaItemDisplay? GetById(Guid id)

Parameters

id Guid

Returns

MediaItemDisplay

GetById(int)

Gets the media item by id

[Authorize(Policy = "MediaPermissionPathById")]
public MediaItemDisplay? GetById(int id)

Parameters

id int

Returns

MediaItemDisplay

GetById(Udi)

Gets the media item by id

[Authorize(Policy = "MediaPermissionPathById")]
public ActionResult<MediaItemDisplay?> GetById(Udi id)

Parameters

id Udi

Returns

ActionResult<MediaItemDisplay>

GetByIds(int[])

Return media for the specified ids

public IEnumerable<MediaItemDisplay?> GetByIds(int[] ids)

Parameters

ids int[]

Returns

IEnumerable<MediaItemDisplay>

GetChildFolders(int, int, int)

Returns a paged result of media items known to be of a "Folder" type

public PagedResult<ContentItemBasic<ContentPropertyBasic>> GetChildFolders(int id, int pageNumber = 1, int pageSize = 1000)

Parameters

id int
pageNumber int
pageSize int

Returns

PagedResult<ContentItemBasic<ContentPropertyBasic>>

GetChildren(Guid, int, int, string, Direction, bool, string)

Returns the child media objects - using the entity GUID id

public ActionResult<PagedResult<ContentItemBasic<ContentPropertyBasic>>> GetChildren(Guid id, int pageNumber = 0, int pageSize = 0, string orderBy = "SortOrder", Direction orderDirection = 0, bool orderBySystemField = true, string filter = "")

Parameters

id Guid
pageNumber int
pageSize int
orderBy string
orderDirection Direction
orderBySystemField bool
filter string

Returns

ActionResult<PagedResult<ContentItemBasic<ContentPropertyBasic>>>

GetChildren(int, int, int, string, Direction, bool, string)

Returns the child media objects - using the entity INT id

public PagedResult<ContentItemBasic<ContentPropertyBasic>> GetChildren(int id, int pageNumber = 0, int pageSize = 0, string orderBy = "SortOrder", Direction orderDirection = 0, bool orderBySystemField = true, string filter = "")

Parameters

id int
pageNumber int
pageSize int
orderBy string
orderDirection Direction
orderBySystemField bool
filter string

Returns

PagedResult<ContentItemBasic<ContentPropertyBasic>>

GetChildren(Udi, int, int, string, Direction, bool, string)

Returns the child media objects - using the entity UDI id

public ActionResult<PagedResult<ContentItemBasic<ContentPropertyBasic>>> GetChildren(Udi id, int pageNumber = 0, int pageSize = 0, string orderBy = "SortOrder", Direction orderDirection = 0, bool orderBySystemField = true, string filter = "")

Parameters

id Udi
pageNumber int
pageSize int
orderBy string
orderDirection Direction
orderBySystemField bool
filter string

Returns

ActionResult<PagedResult<ContentItemBasic<ContentPropertyBasic>>>

GetEmpty(string, int)

Gets an empty content item for the

public ActionResult<MediaItemDisplay?> GetEmpty(string contentTypeAlias, int parentId)

Parameters

contentTypeAlias string
parentId int

Returns

ActionResult<MediaItemDisplay>

GetRecycleBin()

Returns an item to be used to display the recycle bin for media

public MediaItemDisplay GetRecycleBin()

Returns

MediaItemDisplay

GetRootMedia()

Returns the root media objects

public IEnumerable<ContentItemBasic<ContentPropertyBasic>> GetRootMedia()

Returns

IEnumerable<ContentItemBasic<ContentPropertyBasic>>

PostAddFile(string, string, string, List<IFormFile>)

Used to submit a media file

public Task<IActionResult> PostAddFile(string path, string currentFolder, string contentTypeAlias, List<IFormFile> file)

Parameters

path string
currentFolder string
contentTypeAlias string
file List<IFormFile>

Returns

Task<IActionResult>

Remarks

We cannot validate this request with attributes (nicely) due to the nature of the multi-part for data.

PostAddFolder(PostedFolder)

public Task<ActionResult<MediaItemDisplay?>> PostAddFolder(PostedFolder folder)

Parameters

folder PostedFolder

Returns

Task<ActionResult<MediaItemDisplay>>

PostMove(MoveOrCopy)

Change the sort order for media

public Task<IActionResult> PostMove(MoveOrCopy move)

Parameters

move MoveOrCopy

Returns

Task<IActionResult>

PostSave(MediaItemSave)

Saves content

[FileUploadCleanupFilter(true)]
public ActionResult<MediaItemDisplay?>? PostSave(MediaItemSave contentItem)

Parameters

contentItem MediaItemSave

Returns

ActionResult<MediaItemDisplay>

PostSort(ContentSortOrder)

Change the sort order for media

public Task<IActionResult> PostSort(ContentSortOrder sorted)

Parameters

sorted ContentSortOrder

Returns

Task<IActionResult>