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
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, IOptions<ContentSettings>)
Declaration
public MediaFileManager(IFileSystem fileSystem, IMediaPathScheme mediaPathScheme, ILogger<MediaFileManager> logger, IShortStringHelper shortStringHelper, IServiceProvider serviceProvider, IOptions<ContentSettings> contentSettings)
Parameters
Type | Name | Description |
---|---|---|
IFileSystem | fileSystem | |
IMediaPathScheme | mediaPathScheme | |
ILogger<MediaFileManager> | logger | |
IShortStringHelper | shortStringHelper | |
IServiceProvider | serviceProvider | |
IOptions<ContentSettings> | contentSettings |
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. |
System.String | sourcepath | The filesystem-relative path to the source media file. |
Returns
Type | Description |
---|---|
System.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<System.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 | |
System.String | mediaFilePath | The file path if a file was found |
System.String | propertyTypeAlias | |
System.String | culture | |
System.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 |
---|---|---|
System.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 |
---|---|
System.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.
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. |
System.String | filename | The media file name. |
Stream | filestream | A stream containing the media bytes. |
System.String | oldpath | An optional filesystem-relative filepath to the previous media file. |
Returns
Type | Description |
---|---|
System.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.