Class FileStorageService
Service for working with file storage providers.
Implements
Inherited Members
Namespace: DataWeb.Storage
Assembly: DataWeb.Core.dll
Syntax
public class FileStorageService : IFileStorageService
Remarks
Initializes a new instance of the FileStorageService class.
Constructors
FileStorageService(IServiceProvider)
Service for working with file storage providers.
Declaration
public FileStorageService(IServiceProvider serviceProvider)
Parameters
Type | Name | Description |
---|---|---|
IServiceProvider | serviceProvider | The service provider. |
Remarks
Initializes a new instance of the FileStorageService class.
Methods
CloneFileAsync(string, string, string, string, string, CancellationToken)
Clones a file from the source storage container to the target storage container in the specified storage service.
Declaration
public Task<StorageResult> CloneFileAsync(string storageName, string sourceStorageFileName, string sourceStorageContainer, string targetStorageFileName, string targetStorageContainer, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | storageName | The name of the storage service where the file is stored. |
string | sourceStorageFileName | The name of the file to clone. |
string | sourceStorageContainer | The source storage container. |
string | targetStorageFileName | The name for the cloned file. |
string | targetStorageContainer | The target storage container. |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<StorageResult> | A StorageResult indicating the success or failure of the operation. |
DeleteFileAsync(string, string, string, CancellationToken)
Deletes a file from the specified storage service and container.
Declaration
public Task<StorageResult> DeleteFileAsync(string storageName, string storageFileName, string storageContainer, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | storageName | The name of the storage service where the file is stored. |
string | storageFileName | The name of the file to delete. |
string | storageContainer | The storage container where the file is located. |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<StorageResult> | A StorageResult indicating the success or failure of the operation. |
DownloadFileStreamAsync(IFile, CancellationToken)
Gets a stream to download the file from the specified storage provider.
Declaration
public Task<Stream> DownloadFileStreamAsync(IFile file, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
IFile | file | The IFile to download. |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<Stream> | A stream to download the file. |
DownloadFileStreamAsync(string, string, string, string, CancellationToken)
Gets a stream to download the file from the specified storage provider.
Declaration
public Task<Stream> DownloadFileStreamAsync(string storageName, string storageFileName, string storageContainer, string fileDomain = null, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | storageName | The name of the storage provider. |
string | storageFileName | The name of the file in the storage provider. |
string | storageContainer | The name of the storage container in the storage provider. |
string | fileDomain | The domain of the file if applicable. |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<Stream> | A stream to download the file. |
FileExistsAsync(string, string, string, CancellationToken)
Checks if a file exists in the specified storage container.
Declaration
public Task<bool> FileExistsAsync(string storageName, string storageFileName, string storageContainer, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | storageName | The name of the storage provider to use. |
string | storageFileName | The name of the file to check. |
string | storageContainer | The container in which the file should be stored. |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<bool> | True if the file exists, otherwise false. |
GetFilePropertiesAsync(string, string, string, CancellationToken)
Gets the properties of a file in the specified storage container.
Declaration
public Task<StorageFileProperties> GetFilePropertiesAsync(string storageName, string storageFileName, string storageContainer, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | storageName | The name of the storage provider to use. |
string | storageFileName | The name of the file to get the properties for. |
string | storageContainer | The container in which the file should be stored. |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<StorageFileProperties> | The properties of the file. |
GetFileStorageStores()
Returns a collection of all file storage stores associated with this file storage service.
Declaration
public IEnumerable<IFileStorageStore> GetFileStorageStores()
Returns
Type | Description |
---|---|
IEnumerable<IFileStorageStore> | A collection of IFileStorageStore instances. |
GetFileStreamAsync(string, string, string, CancellationToken)
Gets a stream for reading the contents of a file in the specified storage container.
Declaration
public Task<Stream> GetFileStreamAsync(string storageName, string storageFileName, string storageContainer, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | storageName | The name of the storage provider to use. |
string | storageFileName | The name of the file to get the stream for. |
string | storageContainer | The container in which the file should be stored. |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<Stream> | The stream for reading the contents of the file. |
GetNewStorageFileName(string, string, string)
Generates a new unique name for a file in the specified storage container.
Declaration
public string GetNewStorageFileName(string storageName, string fileName, string storageContainer)
Parameters
Type | Name | Description |
---|---|---|
string | storageName | The name of the storage provider to use. |
string | fileName | The original name of the file. |
string | storageContainer | The container in which the file should be stored. |
Returns
Type | Description |
---|---|
string | The new unique file name. |
MoveFileAsync(string, string, string, string, string, CancellationToken)
Moves a file from the source storage container to the target storage container in the specified storage service.
Declaration
public Task<StorageResult> MoveFileAsync(string storageName, string sourceStorageFileName, string sourceStorageContainer, string targetStorageFileName, string targetStorageContainer, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | storageName | The name of the storage service where the file is stored. |
string | sourceStorageFileName | The name of the file to move. |
string | sourceStorageContainer | The source storage container. |
string | targetStorageFileName | The new name for the file after it is moved. |
string | targetStorageContainer | The target storage container. |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<StorageResult> | A StorageResult indicating the success or failure of the operation. |
UploadChunkStreamAsync(string, Stream, int, int, int, long, string, string, CancellationToken)
Uploads a chunk of a file stream to the specified storage provider.
Declaration
public Task<StorageResult> UploadChunkStreamAsync(string storageName, Stream stream, int chunkNumber, int chunkSize, int chunkCount, long storageFileSize, string storageFileName, string storageContainer, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | storageName | The name of the storage provider. |
Stream | stream | The stream to upload. |
int | chunkNumber | The number of the chunk to upload. |
int | chunkSize | The size of each chunk. |
int | chunkCount | The total number of chunks. |
long | storageFileSize | The size of the file being uploaded. |
string | storageFileName | The name of the file in the storage provider. |
string | storageContainer | The name of the storage container in the storage provider. |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<StorageResult> | The result of the upload operation. |
UploadFileStreamAsync(string, Stream, string, string, CancellationToken)
Uploads a stream to the specified storage provider.
Declaration
public Task<StorageResult> UploadFileStreamAsync(string storageName, Stream stream, string storageFileName, string storageContainer, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
string | storageName | The name of the storage provider. |
Stream | stream | The stream to upload. |
string | storageFileName | The name of the file in the storage provider. |
string | storageContainer | The name of the storage container in the storage provider. |
CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
Task<StorageResult> | The result of the upload operation. |