GaEpd.FileService 3.1.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
dotnet add package GaEpd.FileService --version 3.1.1
NuGet\Install-Package GaEpd.FileService -Version 3.1.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="GaEpd.FileService" Version="3.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add GaEpd.FileService --version 3.1.1
#r "nuget: GaEpd.FileService, 3.1.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install GaEpd.FileService as a Cake Addin
#addin nuget:?package=GaEpd.FileService&version=3.1.1

// Install GaEpd.FileService as a Cake Tool
#tool nuget:?package=GaEpd.FileService&version=3.1.1

Georgia EPD-IT File Service Library

This library was created by Georgia EPD-IT to provide common file services for our web applications.

Georgia EPD-IT .NET Test CodeQL SonarCloud Quality Gate Status Lines of Code

Installation

Nuget

To install, search for "GaEpd.FileService" in the NuGet package manager or run the following command:

dotnet add package GaEpd.FileService

Usage

An IFileService interface is used to abstract out common file persistence operations:

  • SaveFileAsync
  • FileExistsAsync
  • GetFilesAsync
  • GetFileAsync
  • TryGetFileAsync
  • DeleteFileAsync

The library also includes three useful implementations, In Memory, File System, and Azure Blob Storage. Each implementation can be registered independently as shown in the sections below.

Alternatively, the AddFileServices extension method can be used to automatically register an implementation based on the configuration. To do so, register the file services configuration as follows:

builder.Services.AddFileServices(builder.Configuration);

And add the following section to your configuration:

{
  "FileServiceSettings": {
    "FileService": "",
    "FileSystemBasePath": "",
    "NetworkUsername": "",
    "NetworkDomain": "",
    "NetworkPassword": "",
    "AzureAccountName": "",
    "BlobContainer": "",
    "BlobBasePath": ""
  }
}

The FileService setting must be set to InMemory, FileSystem, or AzureBlobStorage.

  • If InMemory is chosen, all other settings are ignored.

  • If FileSystem is chosen, then FileSystemBasePath is required, and NetworkUsername, NetworkDomain, and NetworkPassword can be provided if needed. Other settings are ignored.

  • If AzureBlobStorage is chosen, then AzureAccountName and BlobContainer are required, and BlobBasePath can be provided if desired. Other settings are ignored.

In Memory

The in-memory file service implementation stores files in memory.

builder.Services.AddSingleton<IFileService, InMemoryFileService>();

File System

The file system service writes files to a local or network drive. The basePath parameter is required and defines where the files will be stored. If basePath doesn't exist, it will be created.

builder.Services.AddTransient<IFileService, FileSystemFileService>(_ =>
    new FileSystemFileService(basePath));

If a Windows Identity is required to access the desired file location, use the overload that accepts username, domain, and password parameters in the constructor.

builder.Services.AddTransient<IFileService, FileSystemFileService>(_ =>
    new FileSystemFileService(basePath, username, domain, password));

Azure Blob Storage

The Azure Blob Storage service requires an Azure account and an existing Blob Storage container. (The service does not attempt to create the container if it does not exist.) The basePath parameter is optional and is prepended to file names as a path segment. DefaultAzureCredential is used to initialize the BlobServiceClient.

builder.Services.AddSingleton<IFileService, AzureBlobFileService>(_ =>
    new AzureBlobFileService(accountName, container, basePath));

Warning: At the moment, the SaveFileAsync() method throws an exception when using Azure Blob Storage if the file already exists.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.1.1 675 3/5/2024
3.1.0 427 1/25/2024
3.0.0 92 1/24/2024
2.1.0 133 1/16/2024
2.0.0 128 1/2/2024
1.0.0 240 10/25/2023

# Changelog
## [3.1.1]
### Fixed
- Updated `GetFilesAsync` in the `FileSystem` implementation so that it doesn't throw an exception if the path doesn't
exist, making it consistent with the other implementations.
## [3.1.0]
### Changed
- Added `ConfigureAwait(false)` call to awaited tasks.
## [3.0.0]
### Added
- Added a method to list files in a specified path.
### Changed
- **Breaking change** This release changes how paths are built when using Azure Blob Storage in order to avoid platform
inconsistencies. It's possible this could result in `FileExistsAsync` and `GetFilesAsync` failing for existing files.
Thorough testing is recommended when updating.
## [2.1.0]
### Added
- Added an extension method for registering and configuring file services.
## [2.0.0]
- Upgraded to .NET 8.0.
## [1.0.0]
- Initial release.