Empezar.Cloud 1.9.94

There is a newer version of this package available.
See the version list below for details.
dotnet add package Empezar.Cloud --version 1.9.94
                    
NuGet\Install-Package Empezar.Cloud -Version 1.9.94
                    
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.94" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Empezar.Cloud" Version="1.9.94" />
                    
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 1.9.94
                    
#r "nuget: Empezar.Cloud, 1.9.94"
                    
#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=1.9.94
                    
Install Empezar.Cloud as a Cake Addin
#tool nuget:?package=Empezar.Cloud&version=1.9.94
                    
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. 
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.96 140 4/2/2025
1.9.95 472 3/26/2025
1.9.94 461 3/25/2025
1.9.93-alpha 154 3/18/2025
1.9.92-alpha 138 3/18/2025
1.9.91-alpha 136 3/17/2025
1.9.9-alpha 65 3/15/2025
1.9.8-alpha 94 3/14/2025
1.9.7-alpha 96 3/14/2025
1.9.6-alpha 204 3/4/2025
1.9.5-alpha 93 2/27/2025
1.9.4-alpha 89 2/26/2025
1.9.3-alpha 94 2/21/2025
1.9.2-alpha 102 2/14/2025
1.9.1-alpha 103 2/14/2025
1.9.0-alpha 105 2/14/2025
1.1.1.25 354 12/11/2024
1.1.1.24 291 11/25/2024
1.1.1.24-alpha3 97 11/25/2024
1.1.1.24-alpha2 100 11/24/2024
1.1.1.24-alpha1 99 11/22/2024
1.1.1.23 111 11/21/2024
1.1.1.22 354 11/18/2024
1.1.1.21 405 9/3/2024
1.1.1.20 306 7/25/2024
1.1.1.19 249 7/11/2024
1.1.1.18 102 7/11/2024
1.1.1.17 88 7/11/2024
1.1.1.16 246 7/7/2024
1.1.1.15 136 6/27/2024
1.1.1.14 133 6/23/2024
1.1.1.13 115 6/3/2024
1.1.1.12 542 5/6/2024
1.1.1.11 106 5/3/2024
1.1.1.10 203 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 132 3/22/2024
1.1.1.5 149 3/20/2024
1.1.1.4 162 3/19/2024
1.1.1.3 151 3/18/2024
1.1.1.2 161 3/17/2024
1.1.1.1 136 3/17/2024
1.1.1 136 3/16/2024
1.1.0.2 152 3/8/2024
1.1.0.1 175 3/8/2024
1.1.0 134 3/7/2024
1.0.5.18 384 2/3/2024
1.0.5.14 287 1/15/2024
1.0.5.10 127 1/14/2024
1.0.5.9 153 1/14/2024
1.0.5.8 177 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 150 12/10/2023
1.0.2 153 12/9/2023
1.0.1 149 12/9/2023
1.0.0 159 12/5/2023