/FileSizeFromBase64.NET

Get file size from Base64 in NET

Primary LanguageC#MIT LicenseMIT

CI NuGet

FileSizeFromBase64.NET

A .NET Standard 2.1 project containing a single method to get file size from base64 string. The base64 string can contain MIME-type or not. Paddings are also supported in the decoding process, you can define whether the paddings rules should be applied or not.

Installation

You can install the NuGet Package in any .NET Project: .NET, .NET Standard, .NET Core, .NET, Xamarin, Maui, ... etc.

FileSizeFromBase64.NET can be found here on NuGet and can be installed by copying and pasting the following command into your Package Manager Console within Visual Studio (Tools > NuGet Package Manager > Package Manager Console).

Install-Package FileSizeFromBase64.NET

Alternatively, if you're using .NET Core then you can install FileSizeFromBase64.NET via the CLI with the following command:

dotnet add package FileSizeFromBase64.NET

🚀 Install the latest version for better performance

Documentation

using FileSizeFromBase64.NET;

var fileSize = FileSizeHelpers.GetFileSizeFromBase64String(string base64String, bool applyPaddingsRules, UnitsOfMeasurement unitsOfMeasurement)
Parameters Data type Description Required Default Value
base64String string The base64 representation of the file. Yes
applyPaddingsRules boolean Base64 - Padding No false
unitsOfMeasurement Enum The unit of measurement for the file size returned by the method: UnitsOfMeasurement.Byte, UnitsOfMeasurement.KiloByte, UnitsOfMeasurement.MegaByte No UnitsOfMeasurement.Byte

Usage

using FileSizeFromBase64.NET;

// File hello-world.txt => Size = 13 Bytes, Content: Hello world !
var base64String = "data:text/plain;base64,SGVsbG8gd29ybGQgIQ==";

var fileSize = FileSizeHelpers.GetFileSizeFromBase64String(base64String, true);
Console.WriteLine($"File size: {fileSize}");
    
var fileSizeInKB = FileSizeHelpers.GetFileSizeFromBase64String(base64String, true, UnitsOfMeasurement.KiloByte);

var fileSizeInMB = FileSizeHelpers.GetFileSizeFromBase64String(base64String, true, UnitsOfMeasurement.MegaByte);

Created by: Laurent Egbakou

License

The MIT License (MIT) see the License file

Contribution

Feel free to create issues and PRs 😃