Class MediaFileManager
Inheritance
Namespace: Umbraco.Cms.Core.IO
Assembly: Umbraco.Core.dll
Syntax
public sealed class MediaFileManager
Constructors
View SourceMediaFileManager(IFileSystem, IMediaPathScheme, ILogger<MediaFileManager>, IShortStringHelper, IServiceProvider)
Declaration
[Obsolete("Please use the constructor taking all arguments, scheduled for removal in Umbraco 19")]
public MediaFileManager(IFileSystem fileSystem, IMediaPathScheme mediaPathScheme, ILogger<MediaFileManager> logger, IShortStringHelper shortStringHelper, IServiceProvider serviceProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| IFileSystem | fileSystem | |
| IMediaPathScheme | mediaPathScheme | |
| ILogger<MediaFileManager> | logger | |
| IShortStringHelper | shortStringHelper | |
| IServiceProvider | serviceProvider |
MediaFileManager(IFileSystem, IMediaPathScheme, ILogger<MediaFileManager>, IShortStringHelper, IServiceProvider, Lazy<ICoreScopeProvider>)
Declaration
public MediaFileManager(IFileSystem fileSystem, IMediaPathScheme mediaPathScheme, ILogger<MediaFileManager> logger, IShortStringHelper shortStringHelper, IServiceProvider serviceProvider, Lazy<ICoreScopeProvider> coreScopeProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| IFileSystem | fileSystem | |
| IMediaPathScheme | mediaPathScheme | |
| ILogger<MediaFileManager> | logger | |
| IShortStringHelper | shortStringHelper | |
| IServiceProvider | serviceProvider | |
| Lazy<ICoreScopeProvider> | coreScopeProvider |
Properties
View SourceFileSystem
Gets the media filesystem.
Declaration
public IFileSystem FileSystem { get; }
Property Value
| Type | Description |
|---|---|
| IFileSystem |
Methods
View SourceCopyFile(IContentBase, IPropertyType, string)
Copies a media file as a new media file, associated to a property of a content item.
Declaration
public string? CopyFile(IContentBase content, IPropertyType propertyType, string sourcepath)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | content | The content item owning the copy of the media file. |
| IPropertyType | propertyType | The property type owning the copy of the media file. |
| string | sourcepath | The filesystem-relative path to the source media file. |
Returns
| Type | Description |
|---|---|
| string | The filesystem-relative path to the copy of the media file. |
DeleteMediaFiles(IEnumerable<string>)
Delete media files.
Declaration
public void DeleteMediaFiles(IEnumerable<string> files)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<string> | files | Files to delete (filesystem-relative paths). |
GetFile(IContentBase, out string?, string, string?, string?)
Returns a stream (file) for a content item (or a null stream if there is no file).
Declaration
public Stream GetFile(IContentBase content, out string? mediaFilePath, string propertyTypeAlias = "umbracoFile", string? culture = null, string? segment = null)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | content | |
| string | mediaFilePath | The file path if a file was found |
| string | propertyTypeAlias | |
| string | culture | |
| string | segment |
Returns
| Type | Description |
|---|---|
| Stream |
GetMediaPath(string?, Guid, Guid)
Gets the file path of a media file.
Declaration
public string GetMediaPath(string? filename, Guid cuid, Guid puid)
Parameters
| Type | Name | Description |
|---|---|---|
| string | filename | The file name. |
| Guid | cuid | The unique identifier of the content/media owning the file. |
| Guid | puid | The unique identifier of the property type owning the file. |
Returns
| Type | Description |
|---|---|
| string | The filesystem-relative path to the media file. |
Remarks
With the old media path scheme, this CREATES a new media path each time it is invoked.
RemoveSuffixFromMediaFiles(IEnumerable<string>, string)
Removes a suffix from media files.
Declaration
public void RemoveSuffixFromMediaFiles(IEnumerable<string> files, string suffix)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<string> | files | Files to remove a suffix from. |
| string | suffix | The suffix to remove. |
Remarks
The suffix will be removed prior to the file extension, e.g. "image.deleted.jpg" with suffix ".deleted" will become "image.jpg".
StoreFile(IContentBase, IPropertyType?, string, Stream, string?)
Stores a media file associated to a property of a content item.
Declaration
public string StoreFile(IContentBase content, IPropertyType? propertyType, string filename, Stream filestream, string? oldpath)
Parameters
| Type | Name | Description |
|---|---|---|
| IContentBase | content | The content item owning the media file. |
| IPropertyType | propertyType | The property type owning the media file. |
| string | filename | The media file name. |
| Stream | filestream | A stream containing the media bytes. |
| string | oldpath | An optional filesystem-relative filepath to the previous media file. |
Returns
| Type | Description |
|---|---|
| string | The filesystem-relative filepath to the media file. |
Remarks
The file is considered "owned" by the content/propertyType.
If an oldpath is provided then that file (and associated thumbnails if any) is deleted
before the new file is saved, and depending on the media path scheme, the folder may be reused for the new
file.
SuffixMediaFiles(IEnumerable<string>, string)
Adds a suffix to media files.
Declaration
public void SuffixMediaFiles(IEnumerable<string> files, string suffix)
Parameters
| Type | Name | Description |
|---|---|---|
| IEnumerable<string> | files | Files to append a suffix to. |
| string | suffix | The suffix to append. |
Remarks
The suffix will be added prior to the file extension, e.g. "image.jpg" with suffix ".deleted" will become "image.deleted.jpg".