Get file size from base64 string
$ dotnet add package FileSizeFromBase64.NETA .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.
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);
var fileSizeInKB = FileSizeHelpers.GetFileSizeFromBase64String(base64String, true, UnitsOfMeasurement.KiloByte);
var fileSizeInMB = FileSizeHelpers.GetFileSizeFromBase64String(base64String, true, UnitsOfMeasurement.MegaByte);
| Parameter | Type | Description | Required | Default |
|---|---|---|---|---|
base64String | string | The base64 representation of the file. | Yes | |
applyPaddingsRules | bool | Base64 Padding | No | false |
unitsOfMeasurement | Enum | Byte, KiloByte, or MegaByte | No | Byte |
MIT — see LICENSE