Empezar.Cloud
1.9.3-alpha
dotnet add package Empezar.Cloud --version 1.9.3-alpha
NuGet\Install-Package Empezar.Cloud -Version 1.9.3-alpha
<PackageReference Include="Empezar.Cloud" Version="1.9.3-alpha" />
paket add Empezar.Cloud --version 1.9.3-alpha
#r "nuget: Empezar.Cloud, 1.9.3-alpha"
// Install Empezar.Cloud as a Cake Addin #addin nuget:?package=Empezar.Cloud&version=1.9.3-alpha&prerelease // Install Empezar.Cloud as a Cake Tool #tool nuget:?package=Empezar.Cloud&version=1.9.3-alpha&prerelease
Empezar.Cloud
Cloud service encapsulating AWS, GCP & Azure for your application to be truly Cloud agnostic.
Installation
Install the nuget package for Empezar.Cloud in your API Project.
You can also use Manager Nuget Packages
to install the same.
dotnet add package Empezar.Cloud
Usage
Register the cloud service in Program.cs of API project
builder.Services.RegisterCloudService(builder.Configuration["EZRBlazorWebAPI:Cloud:Type"]!,
builder.Configuration["EZRBlazorWebAPI:Cloud:BucketName"]!,
builder.Configuration.GetSection("EZRBlazorWebAPI:Cloud:AllowedFileTypes").Get<string[]>()!.ToImmutableHashSet(StringComparer.InvariantCultureIgnoreCase),
builder.Configuration["EZRBlazorWebAPI:Cloud:AzureBlobConnection"]);
Configurations can be done in appSettings.config or environment valriables as shown below
Valid Type = AWS/GCP/Azure/DEV
"EZRBlazorWebAPI": {
"Cloud": {
"Type": "AWS",
"BucketName": "YourBucketName",
"AllowedFileTypes": [ "docx", "xlsx", "csv", "pdf", "jpeg", "jpg", "png", "zip" ]
}
}
OR
export EZRBlazorWebAPI__Cloud__Type="AWS"
export EZRBlazorWebAPI__Cloud__AzureBlobConnection="YourConnectionString"
You can now inject ICloudService cloudService
in your class or method.
async (CloudFile uploadDoc, [FromHeader(Name = BaseHeaderConstants.XSource)] string source,
ICloudService cloudService, CancellationToken token) =>
{
if (uploadDoc.file == null) return Results.BadRequest(new ProblemDetails { Detail = "File not found" });
else
{
var fileExtn = Empezar.Cloud.Program.GetFileExtention(uploadDoc.file);
if (fileExtn == null) return Results.BadRequest(new ProblemDetails { Detail = "Unsupported file type" });
if (uploadValidator.Invoke(caller, source, fileExtn, uploadDoc.file.Length / (1024.0 * 1024.0)))
return Results.Ok(await cloudService.UploadDocument(uploadDoc.file, uploadDoc.contenttype, token));
else
return Results.BadRequest(new ProblemDetails { Detail = "Unsupported file type or size exceeds the limit" });
}
}
static bool UploadValidator(ClaimsPrincipal caller, string source, string extention, double size)
{
var roles = caller.FindAll(ClaimTypes.Role).Select(x => x.Value);
bool isValid = false;
switch (source)
{
case "source1":
IEnumerable<string> source1FileTypes = FileTypes.GetFileTypes<FileTypes.DocTypes>();
isValid = (roles.Contains("admin") && source1FileTypes.Contains(extention, StringComparer.InvariantCultureIgnoreCase) && size <= 5);
break;
case "source2":
IEnumerable<string> source2FileTypes = FileTypes.GetFileTypes<FileTypes.ImageTypes>();
isValid = (source2FileTypes.Contains(extention, StringComparer.InvariantCultureIgnoreCase) && size <= 1);
break;
}
return isValid;
}
To Download or Delete file, you can use
async (string key, ICloudService cloudService, CancellationToken token) =>
await cloudService.DownloadDocument(Uri.UnescapeDataString(key), token)
async (string key, ICloudService cloudService, CancellationToken token) =>
await cloudService.DeleteDocument(Uri.UnescapeDataString(key), token)
The service implements MimeDetective
package which will provide easy extention methods on your byte[] to validate MIME Type and File Extentions
using magic bytes.
//Gets actual MIME Type
uploadDoc.file.GetMimeType()
//Gets actual File Extention
uploadDoc.file.GetFileExtention()
License
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
-
net9.0
- AWSSDK.S3 (>= 3.7.415.3)
- Azure.Storage.Blobs (>= 12.23.0)
- Google.Cloud.Storage.V1 (>= 4.10.0)
- Mime-Detective (>= 24.12.2)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Empezar.Cloud:
Package | Downloads |
---|---|
Empezar.API
Package Description |
|
Empezar.BlazorWebAPI
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.9.3-alpha | 50 | 2/21/2025 |
1.9.2-alpha | 71 | 2/14/2025 |
1.9.1-alpha | 72 | 2/14/2025 |
1.9.0-alpha | 76 | 2/14/2025 |
1.1.1.25 | 203 | 12/11/2024 |
1.1.1.24 | 177 | 11/25/2024 |
1.1.1.24-alpha3 | 86 | 11/25/2024 |
1.1.1.24-alpha2 | 90 | 11/24/2024 |
1.1.1.24-alpha1 | 89 | 11/22/2024 |
1.1.1.23 | 102 | 11/21/2024 |
1.1.1.22 | 291 | 11/18/2024 |
1.1.1.21 | 366 | 9/3/2024 |
1.1.1.20 | 264 | 7/25/2024 |
1.1.1.19 | 242 | 7/11/2024 |
1.1.1.18 | 96 | 7/11/2024 |
1.1.1.17 | 83 | 7/11/2024 |
1.1.1.16 | 240 | 7/7/2024 |
1.1.1.15 | 130 | 6/27/2024 |
1.1.1.14 | 127 | 6/23/2024 |
1.1.1.13 | 109 | 6/3/2024 |
1.1.1.12 | 536 | 5/6/2024 |
1.1.1.11 | 102 | 5/3/2024 |
1.1.1.10 | 200 | 4/17/2024 |
1.1.1.9 | 189 | 4/8/2024 |
1.1.1.8 | 248 | 4/1/2024 |
1.1.1.7 | 234 | 3/22/2024 |
1.1.1.6 | 127 | 3/22/2024 |
1.1.1.5 | 147 | 3/20/2024 |
1.1.1.4 | 159 | 3/19/2024 |
1.1.1.3 | 149 | 3/18/2024 |
1.1.1.2 | 158 | 3/17/2024 |
1.1.1.1 | 131 | 3/17/2024 |
1.1.1 | 134 | 3/16/2024 |
1.1.0.2 | 148 | 3/8/2024 |
1.1.0.1 | 173 | 3/8/2024 |
1.1.0 | 132 | 3/7/2024 |
1.0.5.18 | 378 | 2/3/2024 |
1.0.5.14 | 281 | 1/15/2024 |
1.0.5.10 | 123 | 1/14/2024 |
1.0.5.9 | 150 | 1/14/2024 |
1.0.5.8 | 173 | 1/11/2024 |
1.0.5 | 319 | 12/28/2023 |
1.0.4.65 | 150 | 12/28/2023 |
1.0.4 | 275 | 12/11/2023 |
1.0.3 | 146 | 12/10/2023 |
1.0.2 | 147 | 12/9/2023 |
1.0.1 | 146 | 12/9/2023 |
1.0.0 | 154 | 12/5/2023 |