Empezar.Cloud 2.0.6

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Empezar.Cloud --version 2.0.6
                    
NuGet\Install-Package Empezar.Cloud -Version 2.0.6
                    
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="2.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Empezar.Cloud" Version="2.0.6" />
                    
Directory.Packages.props
<PackageReference Include="Empezar.Cloud" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Empezar.Cloud --version 2.0.6
                    
#r "nuget: Empezar.Cloud, 2.0.6"
                    
#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.
#addin nuget:?package=Empezar.Cloud&version=2.0.6
                    
Install Empezar.Cloud as a Cake Addin
#tool nuget:?package=Empezar.Cloud&version=2.0.6
                    
Install Empezar.Cloud as a Cake Tool

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.  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. 
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
2.0.6.1-alpha 73 5/30/2025
2.0.6 137 5/28/2025
2.0.5 103 5/23/2025
2.0.4 93 5/23/2025
2.0.3 108 5/23/2025
2.0.2 113 5/23/2025
2.0.1 141 5/22/2025
2.0.0 173 4/24/2025
1.9.99 155 4/24/2025
1.9.98 163 4/22/2025
1.9.97 192 4/16/2025
1.9.96 195 4/2/2025
1.9.95 581 3/26/2025
1.9.94 481 3/25/2025
1.9.93-alpha 161 3/18/2025
1.9.92-alpha 144 3/18/2025
1.9.91-alpha 141 3/17/2025
1.9.9-alpha 70 3/15/2025
1.9.8-alpha 99 3/14/2025
1.9.7-alpha 100 3/14/2025
1.9.6-alpha 208 3/4/2025
1.9.5-alpha 95 2/27/2025
1.9.4-alpha 92 2/26/2025
1.9.3-alpha 96 2/21/2025
1.9.2-alpha 106 2/14/2025
1.9.1-alpha 109 2/14/2025
1.9.0-alpha 110 2/14/2025
1.1.1.25 459 12/11/2024
1.1.1.24 405 11/25/2024
1.1.1.24-alpha3 102 11/25/2024
1.1.1.24-alpha2 106 11/24/2024
1.1.1.24-alpha1 104 11/22/2024
1.1.1.23 125 11/21/2024
1.1.1.22 427 11/18/2024
1.1.1.21 428 9/3/2024
1.1.1.20 320 7/25/2024
1.1.1.19 264 7/11/2024
1.1.1.18 118 7/11/2024
1.1.1.17 102 7/11/2024
1.1.1.16 260 7/7/2024
1.1.1.15 151 6/27/2024
1.1.1.14 148 6/23/2024
1.1.1.13 129 6/3/2024
1.1.1.12 556 5/6/2024
1.1.1.11 121 5/3/2024
1.1.1.10 219 4/17/2024
1.1.1.9 206 4/8/2024
1.1.1.8 265 4/1/2024
1.1.1.7 251 3/22/2024
1.1.1.6 148 3/22/2024
1.1.1.5 165 3/20/2024
1.1.1.4 177 3/19/2024
1.1.1.3 166 3/18/2024
1.1.1.2 176 3/17/2024
1.1.1.1 151 3/17/2024
1.1.1 152 3/16/2024
1.1.0.2 168 3/8/2024
1.1.0.1 190 3/8/2024
1.1.0 151 3/7/2024
1.0.5.18 398 2/3/2024
1.0.5.14 302 1/15/2024
1.0.5.10 141 1/14/2024
1.0.5.9 169 1/14/2024
1.0.5.8 191 1/11/2024
1.0.5 335 12/28/2023
1.0.4.65 167 12/28/2023
1.0.4 291 12/11/2023
1.0.3 164 12/10/2023
1.0.2 168 12/9/2023
1.0.1 163 12/9/2023
1.0.0 173 12/5/2023