Base64Helper

Saving Decoded Data

SaveTo writes the decoded bytes from the Base64 input (set via WithInput) to the specified GPALFile path. If the filename has no extension or has a generic one, GPAL uses the GuessExtensionFromBytes result to determine the correct extension. GuessExtensionFromBytes inspects the first few bytes of binary data (magic bytes) to determine the file type - returns a string like '.pdf', '.png', or '.zip'.

Examples

GPAL Fluent: High-level fluent C# API

//GuessExtensionFromBytes reads the file signature (magic bytes at the start of the data) to identify the format. It handles common formats like PDF, PNG, JPEG, GIF, ZIP, and Office documents.

// Decode and save, letting GPAL pick the extension

GPAL.Base64

.WithInput(base64FileData)

.SaveTo(GPAL.FileFor("C:\downloads\file"));

// GPAL auto-detects extension from bytes


// Manually guess the extension from bytes

byte[] fileBytes = Convert.FromBase64String(base64String);

string ext = GPAL.Base64.GuessExtensionFromBytes(fileBytes);

string path = $"C:\output\document{ext}";

GPAL.Base64

.WithInput(base64String)

.SaveTo(GPAL.FileFor(path));

💬 Ask GPAL