Empezar.Cloud 1.9.6-alpha

This is a prerelease version of Empezar.Cloud.
dotnet add package Empezar.Cloud --version 1.9.6-alpha                
NuGet\Install-Package Empezar.Cloud -Version 1.9.6-alpha                
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="Empezar.Cloud" Version="1.9.6-alpha" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Empezar.Cloud --version 1.9.6-alpha                
#r "nuget: Empezar.Cloud, 1.9.6-alpha"                
#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 Empezar.Cloud as a Cake Addin
#addin nuget:?package=Empezar.Cloud&version=1.9.6-alpha&prerelease

// Install Empezar.Cloud as a Cake Tool
#tool nuget:?package=Empezar.Cloud&version=1.9.6-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

MIT

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.6-alpha 186 3/4/2025
1.9.5-alpha 82 2/27/2025
1.9.4-alpha 76 2/26/2025
1.9.3-alpha 85 2/21/2025
1.9.2-alpha 91 2/14/2025
1.9.1-alpha 93 2/14/2025
1.9.0-alpha 94 2/14/2025
1.1.1.25 314 12/11/2024
1.1.1.24 226 11/25/2024
1.1.1.24-alpha3 92 11/25/2024
1.1.1.24-alpha2 95 11/24/2024
1.1.1.24-alpha1 94 11/22/2024
1.1.1.23 106 11/21/2024
1.1.1.22 333 11/18/2024
1.1.1.21 388 9/3/2024
1.1.1.20 305 7/25/2024
1.1.1.19 248 7/11/2024
1.1.1.18 100 7/11/2024
1.1.1.17 87 7/11/2024
1.1.1.16 244 7/7/2024
1.1.1.15 135 6/27/2024
1.1.1.14 131 6/23/2024
1.1.1.13 115 6/3/2024
1.1.1.12 539 5/6/2024
1.1.1.11 106 5/3/2024
1.1.1.10 202 4/17/2024
1.1.1.9 192 4/8/2024
1.1.1.8 250 4/1/2024
1.1.1.7 236 3/22/2024
1.1.1.6 131 3/22/2024
1.1.1.5 149 3/20/2024
1.1.1.4 161 3/19/2024
1.1.1.3 151 3/18/2024
1.1.1.2 160 3/17/2024
1.1.1.1 135 3/17/2024
1.1.1 136 3/16/2024
1.1.0.2 151 3/8/2024
1.1.0.1 175 3/8/2024
1.1.0 134 3/7/2024
1.0.5.18 383 2/3/2024
1.0.5.14 286 1/15/2024
1.0.5.10 126 1/14/2024
1.0.5.9 152 1/14/2024
1.0.5.8 176 1/11/2024
1.0.5 321 12/28/2023
1.0.4.65 152 12/28/2023
1.0.4 277 12/11/2023
1.0.3 149 12/10/2023
1.0.2 150 12/9/2023
1.0.1 149 12/9/2023
1.0.0 158 12/5/2023