SmooAI.File
2.2.4
dotnet add package SmooAI.File --version 2.2.4
NuGet\Install-Package SmooAI.File -Version 2.2.4
<PackageReference Include="SmooAI.File" Version="2.2.4" />
<PackageVersion Include="SmooAI.File" Version="2.2.4" />
<PackageReference Include="SmooAI.File" />
paket add SmooAI.File --version 2.2.4
#r "nuget: SmooAI.File, 2.2.4"
#:package SmooAI.File@2.2.4
#addin nuget:?package=SmooAI.File&version=2.2.4
#tool nuget:?package=SmooAI.File&version=2.2.4
SmooAI.File
Magic-byte MIME detection, typed validation errors, and stream helpers for .NET — because Content-Type headers lie.
.NET port of @smooai/file. Built on Mime-Detective for real MIME sniffing (not extension guessing). Wire-compatible semantics with the TypeScript, Python, Go, and Rust ports.
Install
dotnet add package SmooAI.File
Need S3 upload/download helpers? Add the companion package:
dotnet add package SmooAI.File.S3
Split on purpose — apps that only need MIME detection and validation don't pull in AWSSDK.S3.
Quick start
using SmooAI.File;
// From an ASP.NET Core upload
await using var upload = formFile.OpenReadStream();
var file = await SmooFile.CreateFromStreamAsync(upload, options =>
{
options.Name = formFile.FileName;
options.ExpectedMimeType = formFile.ContentType; // client-claimed
options.MaxSizeBytes = 10_000_000;
options.AllowedMimeTypes = new[] { "image/png", "image/jpeg", "application/pdf" };
});
// One call — throws typed exceptions on violation
file.Validate();
// Detected MIME reflects what the bytes *actually* are
Console.WriteLine(file.Detected.MimeType); // e.g. "image/png"
// Emit as base64 for an email attachment / data URL
var b64 = await file.ToBase64Async();
// Or persist
await file.SaveToFileAsync("/tmp/upload.bin");
Why magic-byte detection
File extensions and Content-Type headers are untrusted client input. file.docx may actually be a ZIP. A .php can masquerade as image/png. SmooFile.Detected.MimeType reflects the real bytes — and Validate(expectedMimeType: …) throws FileContentMismatchException the moment claim disagrees with content.
// Client uploads a PHP shell renamed to avatar.png
var file = await SmooFile.CreateFromStreamAsync(stream, opts =>
{
opts.Name = "avatar.png";
opts.ExpectedMimeType = "image/png";
});
file.Validate(allowedMimes: new[] { "image/png", "image/jpeg" });
// -> throws FileContentMismatchException
// Detected: "text/x-php", Expected: "image/png"
Validation errors
One base class — one catch block on the controller. All typed, all actionable, all 400-worthy:
| Exception | When |
|---|---|
FileSizeException |
File exceeds maxSize |
FileMimeException |
MIME not in allowedMimes |
FileContentMismatchException |
Client-claimed MIME disagrees with magic-byte-detected MIME |
FileValidationException |
Base class — catch this to handle all validation failures |
try
{
file.Validate();
}
catch (FileValidationException ex)
{
return Results.Problem(ex.Message, statusCode: 400);
}
Creating from other sources
// From a byte buffer
var file = await SmooFile.CreateFromBytesAsync(bytes, opts => { opts.Name = "thing.bin"; });
// From a file path
var file = await SmooFile.CreateFromPathAsync("/tmp/upload.bin");
// From a URL (streams, doesn't buffer the full body into memory)
var file = await SmooFile.CreateFromUrlAsync("https://example.com/report.pdf");
Related
SmooAI.File.S3— presigned uploads + S3 helpers (split package)@smooai/file— TypeScript / Nodesmooai-file— Rustsmooai-file— Pythongithub.com/SmooAI/file/go/file— Go
License
MIT — © SmooAI
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. 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. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Mime-Detective (>= 25.8.1)
- Mime-Detective.Definitions.Exhaustive (>= 25.8.1)
-
net8.0
- Mime-Detective (>= 25.8.1)
- Mime-Detective.Definitions.Exhaustive (>= 25.8.1)
-
net9.0
- Mime-Detective (>= 25.8.1)
- Mime-Detective.Definitions.Exhaustive (>= 25.8.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on SmooAI.File:
| Package | Downloads |
|---|---|
|
SmooAI.File.S3
S3 helpers for SmooAI.File — createPresignedUploadUrl, createFromS3, uploadToS3, saveToS3. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.2.4 | 112 | 4/24/2026 |