Class MediaService
Provides functionalities to manage media files.
Implements
Inherited Members
Namespace: DataWeb.Media
Assembly: DataWeb.Core.dll
Syntax
public class MediaService : IMediaService
Remarks
Initializes a new instance of the MediaService class.
Constructors
MediaService(LinkGenerator, IConfigurationService, IEnvironmentService, IFileStorageService)
Provides functionalities to manage media files.
Declaration
public MediaService(LinkGenerator linkGenerator, IConfigurationService configurationService, IEnvironmentService environmentService, IFileStorageService fileStorageService)
Parameters
Type | Name | Description |
---|---|---|
LinkGenerator | linkGenerator | The link generator. |
IConfigurationService | configurationService | The configuration service. |
IEnvironmentService | environmentService | The environment service. |
IFileStorageService | fileStorageService | The file storage service. |
Remarks
Initializes a new instance of the MediaService class.
Methods
BytesToString(long)
Converts a byte count into a string representation that includes the appropriate units (B, KB, MB, GB, TB, PB, or EB).
Declaration
public string BytesToString(long byteCount)
Parameters
Type | Name | Description |
---|---|---|
long | byteCount | The number of bytes to convert. |
Returns
Type | Description |
---|---|
string | A string representation of the byte count, including units. |
GetAppActualSize()
Gets the actual size of the app in bytes.
Declaration
public long GetAppActualSize()
Returns
Type | Description |
---|---|
long | The actual size of the app in bytes. |
GetAppMaxSize()
Gets the maximum app storage size in bytes as defined in appSettings.
Declaration
public long GetAppMaxSize()
Returns
Type | Description |
---|---|
long | The maximum app storage size in bytes. |
GetDefaultUploadMaxFileSize()
Gets the default maximum file upload size in bytes.
Declaration
public long GetDefaultUploadMaxFileSize()
Returns
Type | Description |
---|---|
long | The default maximum file upload size in bytes. |
GetDocumentUrl(string, string, object)
Gets the URL for a document with the specified code.
Declaration
public string GetDocumentUrl(string routeName, string code, object routeValues = null)
Parameters
Type | Name | Description |
---|---|---|
string | routeName | The name of the route to generate the URL. |
string | code | The code of the document. |
object | routeValues | Additional route values to include in the URL. |
Returns
Type | Description |
---|---|
string | The URL for the document. |
GetImageUrl(string, string, int, int, ResizeMode, object)
Gets the URL for an image with the specified code, width, height, and resize mode.
Declaration
public string GetImageUrl(string routeName, string code, int width, int height, ResizeMode mode = ResizeMode.Fix, object routeValues = null)
Parameters
Type | Name | Description |
---|---|---|
string | routeName | The name of the route to generate the URL. |
string | code | The code of the image. |
int | width | The desired width of the image. |
int | height | The desired height of the image. |
ResizeMode | mode | The desired ResizeMode. |
object | routeValues | Additional route values to include in the URL. |
Returns
Type | Description |
---|---|
string | The URL for the image. |
GetMimeTypeByExtension(string)
Retrieves the MIME type for a file extension.
Declaration
public string GetMimeTypeByExtension(string extension)
Parameters
Type | Name | Description |
---|---|---|
string | extension | The file extension to get the MIME type for. |
Returns
Type | Description |
---|---|
string | The MIME type for the given file extension. |
GetNewFileCode()
Generate a new File code.
Declaration
public string GetNewFileCode()
Returns
Type | Description |
---|---|
string | A string representing the new File code. |
SanitizeFileName(string)
Replaces invalid characters in a file name with underscores.
Declaration
public string SanitizeFileName(string fileName)
Parameters
Type | Name | Description |
---|---|---|
string | fileName | The file name to sanitize. |
Returns
Type | Description |
---|---|
string | The sanitized file name. |
UploadChunkStreamAsync(string, Stream, int, int, int, long, string, string, string)
Uploads a chunk of a file to the specified storage using a stream.
Declaration
public Task<SaveUploadStreamResult> UploadChunkStreamAsync(string storageName, Stream stream, int chunkNumber, int chunkSize, int chunkCount, long fileSize, string fileId, string fileExtension, string storageContainer)
Parameters
Type | Name | Description |
---|---|---|
string | storageName | The name of the storage where the file chunk will be uploaded. |
Stream | stream | The stream containing the file chunk to be uploaded. |
int | chunkNumber | The number of the chunk being uploaded. |
int | chunkSize | The size of each chunk in bytes. |
int | chunkCount | The total number of chunks the file will be divided into. |
long | fileSize | The size of the entire file in bytes. |
string | fileId | The Id of the file being uploaded. If this is null or empty, a new Id will be generated. |
string | fileExtension | The extension of the file being uploaded. |
string | storageContainer | The container where the file chunk will be uploaded. |
Returns
Type | Description |
---|---|
Task<SaveUploadStreamResult> | A SaveUploadStreamResult object indicating whether the upload was successful, and any error messages. |