Empezar.Mobile
2.2.0
dotnet add package Empezar.Mobile --version 2.2.0
NuGet\Install-Package Empezar.Mobile -Version 2.2.0
<PackageReference Include="Empezar.Mobile" Version="2.2.0" />
<PackageVersion Include="Empezar.Mobile" Version="2.2.0" />
<PackageReference Include="Empezar.Mobile" />
paket add Empezar.Mobile --version 2.2.0
#r "nuget: Empezar.Mobile, 2.2.0"
#:package Empezar.Mobile@2.2.0
#addin nuget:?package=Empezar.Mobile&version=2.2.0
#tool nuget:?package=Empezar.Mobile&version=2.2.0
Empezar.Mobile
Mobile platform services for Android, iOS & Windows for your application to be truly platform agnostic.
Installation
Install the nuget package for Empezar.Mobile in your API Project.
You can also use Manager Nuget Packages to install the same.
dotnet add package Empezar.Mobile
Usage
Register the Mobile services in Program.cs of MAUI 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 | net10.0-android36.0 is compatible. net10.0-ios26.0 is compatible. net10.0-maccatalyst26.0 is compatible. net10.0-windows10.0.19041 is compatible. |
-
net10.0-android36.0
- Empezar.Interfaces (>= 2.2.0)
- Microsoft.Extensions.Http (>= 10.0.2)
- Microsoft.Identity.Client (>= 4.81.0)
- Microsoft.Maui.Controls (>= 10.0.30)
-
net10.0-ios26.0
- Empezar.Interfaces (>= 2.2.0)
- Microsoft.Extensions.Http (>= 10.0.2)
- Microsoft.Identity.Client (>= 4.81.0)
- Microsoft.Maui.Controls (>= 10.0.30)
-
net10.0-maccatalyst26.0
- Empezar.Interfaces (>= 2.2.0)
- Microsoft.Extensions.Http (>= 10.0.2)
- Microsoft.Identity.Client (>= 4.81.0)
- Microsoft.Maui.Controls (>= 10.0.30)
-
net10.0-windows10.0.19041
- Empezar.Interfaces (>= 2.2.0)
- Microsoft.Extensions.Http (>= 10.0.2)
- Microsoft.Identity.Client (>= 4.81.0)
- Microsoft.Maui.Controls (>= 10.0.30)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.