Class BlobStorageService
- Namespace
- FoundationaLLM.Common.Services.Storage
- Assembly
- FoundationaLLM.Common.dll
Provides access to Azure blob storage.
public class BlobStorageService : StorageServiceBase, IStorageService
- Inheritance
-
BlobStorageService
- Implements
- Inherited Members
- Extension Methods
Remarks
Initializes a new instance of the BlobStorageService with the specified options and logger.
Constructors
BlobStorageService(IOptions<BlobStorageServiceSettings>, ILogger<BlobStorageService>)
Provides access to Azure blob storage.
public BlobStorageService(IOptions<BlobStorageServiceSettings> storageOptions, ILogger<BlobStorageService> logger)
Parameters
storageOptions
IOptions<BlobStorageServiceSettings>The options object containing the BlobStorageServiceSettings object with the settings.
logger
ILogger<BlobStorageService>The logger used for logging.
Remarks
Initializes a new instance of the BlobStorageService with the specified options and logger.
Methods
CreateClientFromAccountKey(string, string)
Creates a storage client from an account name and an account key.
protected override void CreateClientFromAccountKey(string accountName, string accountKey)
Parameters
CreateClientFromConnectionString(string)
Creates a storage client from a connection string.
protected override void CreateClientFromConnectionString(string connectionString)
Parameters
connectionString
stringThe storage connection string.
CreateClientFromIdentity(string)
Create a storage client from an account name using the default identity for authentication.
protected override void CreateClientFromIdentity(string accountName)
Parameters
accountName
stringThe storage account name.
DeleteFileAsync(string, string, CancellationToken)
Deletes a file from storage.
public Task DeleteFileAsync(string containerName, string filePath, CancellationToken cancellationToken = default)
Parameters
containerName
stringThe name of the container where the file is located.
filePath
stringThe path of the file to delete.
cancellationToken
CancellationTokenThe cancellation token that signals that operations should be cancelled.
Returns
FileExistsAsync(string, string, CancellationToken)
Checks if a file exists on the storage.
public Task<bool> FileExistsAsync(string containerName, string filePath, CancellationToken cancellationToken = default)
Parameters
containerName
stringThe name of the container where the file is located.
filePath
stringThe path of the file to read.
cancellationToken
CancellationTokenThe cancellation token that signals that operations should be cancelled.
Returns
GetFilePathsAsync(string, string?, bool, CancellationToken)
Retrieves a list file paths in the specific directory.
public Task<List<string>> GetFilePathsAsync(string containerName, string? directoryPath = null, bool recursive = true, CancellationToken cancellationToken = default)
Parameters
containerName
stringName of the container, file system or Workspace name.
directoryPath
stringDirectory to list file contents
recursive
boolRecurse through child folders
cancellationToken
CancellationTokenDetermines if a request should be cancelled.
Returns
ReadFileAsync(string, string, CancellationToken)
Reads the binary content of a specified file from the storage.
public Task<BinaryData> ReadFileAsync(string containerName, string filePath, CancellationToken cancellationToken = default)
Parameters
containerName
stringThe name of the container where the file is located.
filePath
stringThe path of the file to read.
cancellationToken
CancellationTokenThe cancellation token that signals that operations should be cancelled.
Returns
- Task<BinaryData>
The binary content of the file.
WriteFileAsync(string, string, Stream, string?, CancellationToken)
Writes the binary content to a specified file from the storage.
public Task WriteFileAsync(string containerName, string filePath, Stream fileContent, string? contentType, CancellationToken cancellationToken = default)
Parameters
containerName
stringThe name of the container where the file is located.
filePath
stringThe path of the file to read.
fileContent
StreamThe binary content written to the file.
contentType
stringAn optional content type.
cancellationToken
CancellationTokenThe cancellation token that signals that operations should be cancelled.
Returns
WriteFileAsync(string, string, string, string?, CancellationToken)
Writes the string content to a specified file from the storage.
public Task WriteFileAsync(string containerName, string filePath, string fileContent, string? contentType, CancellationToken cancellationToken = default)
Parameters
containerName
stringThe name of the container where the file is located.
filePath
stringThe path of the file to read.
fileContent
stringThe string content written to the file.
contentType
stringAn optional content type.
cancellationToken
CancellationTokenThe cancellation token that signals that operations should be cancelled.