Promact.FileService.Abstractions
1.0.0
See the version list below for details.
dotnet add package Promact.FileService.Abstractions --version 1.0.0
NuGet\Install-Package Promact.FileService.Abstractions -Version 1.0.0
<PackageReference Include="Promact.FileService.Abstractions" Version="1.0.0" />
<PackageVersion Include="Promact.FileService.Abstractions" Version="1.0.0" />
<PackageReference Include="Promact.FileService.Abstractions" />
paket add Promact.FileService.Abstractions --version 1.0.0
#r "nuget: Promact.FileService.Abstractions, 1.0.0"
#:package Promact.FileService.Abstractions@1.0.0
#addin nuget:?package=Promact.FileService.Abstractions&version=1.0.0
#tool nuget:?package=Promact.FileService.Abstractions&version=1.0.0
file-service
File Service is a versatile repository facilitating seamless file uploads to cloud storage providers such as AWS S3, Azure. IFileService<TFileModel> is generic over the provider's file model type, so the compiler — not a runtime check — enforces that you're using the file model that matches your registered provider. Developed with modularity and ease of integration in mind.
Usage
Inject IFileService<S3FileModel> (AWS) or IFileService<AzureBlobFileModel> (Azure) — whichever matches the provider you registered in DI (see the AWS/Azure sections below). IFileService<TFileModel>, FileModelBase, and GetAllKeysRequest live in Promact.FileService.Abstractions; S3FileModel is in Promact.FileService.AWS and AzureBlobFileModel is in Promact.FileService.Azure.
using Promact.FileService.Abstractions;
using Promact.FileService.AWS; // or Promact.FileService.Azure
private IFileService<S3FileModel> _fileService // or IFileService<AzureBlobFileModel> for Azure
public async Task MyMethod()
{
// For AWS:
var fileModel = new S3FileModel
{
BucketName = "my_Bucket",
KeyName = "FileName",
FilePath = "path/to/file.txt"
};
// For Azure, use an AzureBlobFileModel instead:
// var fileModel = new AzureBlobFileModel
// {
// ContainerName = "my_container",
// KeyName = "FileName",
// FilePath = "path/to/file.txt"
// };
// Call the FileService method to upload the file
await _fileService.UploadFileAsync(fileModel);
// Call the FileService method to check whether the file exists
var exists = await _fileService.CheckFileExistsAsync(fileModel);
// Call the FileService method to get the content of the file as a byte array
var fileBytes = await _fileService.GetFileAsBytesAsync(fileModel);
// Call the FileService method to delete the file
await _fileService.DeleteFileAsync(fileModel);
// In the Case of Azure You get the Link by GetSignedUrlAsync method but you did not have
// permission to Acess So for Acess You Go Azure Portal >> Your storage >> Settings
// >> Configuration >> Allow Blob anonymous access >> Enabled
// Then After >> Your Container >> Change Access Level >> Blob (Read Only)
// Call the FileService method with expiration time to Get the url of file
TimeSpan expiration = TimeSpan.FromHours(1);
var signedUrl = await _fileService.GetSignedUrlAsync(fileModel, expiration);
//Describe the pageno and pagesize for retriving keys in particular page
var request = new GetAllKeysRequest
{
BucketOrContainer = "my_container",
PageNumber = pgno,
PageSize = Size_of_one_page,
};
var keys = await _fileService.GetKeysAsync(request);
//foreach (var key in keys)
//{
// Console.WriteLine(key);
//}
}
Every method above also accepts an optional trailing CancellationToken.
AWS
Add nuget package
Promact.FileService.AWS
ASP.NET Core projects
Add below in Program.cs
builder.Services.AddAWSFileService(options =>
{
options.AccessKey = Configuration.GetSection("AWS:AccessKeyId").Value;
options.SecretKey = Configuration.GetSection("AWS:SecretAccessKey").Value;
options.Region = Configuration.GetSection("AWS:Region").Value;
});
Add relevant appsettings.json values
"AWS": {
"AccessKeyID": "",
"SecretAccessKey": "",
"Region": ""
}
Inject IFileService<S3FileModel> in class constructor from where you want to perform various files operation.
public MyClass(IFileService<S3FileModel> fileService)
{
...
}
Azure
Add nuget package
Promact.FileService.Azure
ASP.NET Core projects
Add below in Program.cs
// Register BlobServiceClient
builder.Services.AddAzureFileService(options =>
{
options.ConnectionString = Configuration.GetSection("Azure:ConnectionString").Value;
});
Add relevant appsettings.json values
"Azure": {
"ConnectionString": ""
},
Inject IFileService<AzureBlobFileModel> in class constructor from where you want to perform various files operation.
public MyClass(IFileService<AzureBlobFileModel> fileService)
{
...
}
| Product | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.