MindAttic/MindAttic.Storage
Library

MindAttic.Storage.

File uploads for ASP.NET Core in two lines.

MindAttic.Storage gives an ASP.NET Core app one upload API, a catalog row per file and a /_media/{uid} endpoint that streams safely with range support, so media handling stops being a weekend project.

Released 1.0 C# .NET 10 ASP.NET Core EF Core SQL Server NuGet

What it is

Uploads, catalog and serving, done properly

Every app that accepts files ends up rebuilding the same plumbing: stream the upload, record it, serve it back with the right headers, and make sure nobody can upload a page that runs script on your origin. MindAttic.Storage packages that plumbing into two registration lines and one endpoint mapping.

Uploads stream through in a single pass that computes size and SHA-256 without buffering the file in memory, so gigabyte uploads are as safe as thumbnails. Small payloads stay inline in the database row; larger ones spill to disk under a stable GUID. Every file is referred to by that one uid, so the storage layout can always be rebuilt from the catalog.

Serving is careful by default. /_media/{uid} answers with Range processing, an ETag from the SHA-256, Last-Modified and nosniff. Images, video, audio, text and PDF display inline; HTML, SVG, XML, JavaScript and anything unparseable download as attachments under a sandboxing Content-Security-Policy.

It ships as two NuGet packages: MindAttic.Storage with the abstraction, EF Core model, local-disk store and endpoint, and MindAttic.Storage.Azure, an Azure Blob backend with a URL signer that is kept for existing consumers but frozen now that MindAttic runs on local storage.

Who it's for

  • ASP.NET Core developersAdd uploads, a media catalog and a correct serving endpoint without writing any of it yourself.
  • Teams handling large mediaStream multi-gigabyte video uploads in one pass and serve them back with seeking.
  • Security-minded maintainersUploaded active content can never render inline on your origin; it downloads in a sandbox.

Features

What you get

01

One store interface

IMediaStore offers UploadAsync, ListAsync by tenant, folder and media type, GetMetaAsync, GetAsync with a content stream, and DeleteAsync.

02

A real catalog row

Each MediaItem records uid, tenant, folder, file name, content type, size, SHA-256, dimensions, notes, timestamps and a row version, with indexes on uid, hash and tenant/folder/name.

03

Inline or on disk, decided while streaming

Payloads up to 2 MB (configurable) stay in the row; larger ones spill to MediaRoot/{uid}/{file}. ThresholdSpillStream decides without knowing the length up front.

04

One-pass hashing

Size and SHA-256 are computed in flight during the copy, so even huge uploads are never buffered in memory.

05

A media endpoint that does it right

/_media/{uid} streams with Range requests, ETag, Last-Modified and a private cache max-age, or redirects to a stored absolute URL.

06

Safe with untrusted uploads

HTML, SVG, XML, JavaScript and unparseable types download as attachments with Content-Security-Policy: sandbox; every response carries X-Content-Type-Options: nosniff.

07

Cross-platform file-name sanitizing

Path segments and Windows-invalid characters are stripped the same way on every OS, while rows stored under the earlier rule keep resolving.

08

No orphans, soft deletes

A cancelled or failed upload removes its spill file or partial blob. Deletes are soft, so a mistake is recoverable.

09

Optional Azure Blob backend

AddMediaAzure streams to a blob container and hands browsers signed, public or CDN URLs. It remains available for existing consumers and is frozen for new work.

How it works

Add uploads to your app

  1. Reference the package

    Add MindAttic.Storage from your NuGet feed.

  2. Map the catalog

    Apply MediaItemTypeConfiguration in your DbContext and add an EF Core migration for the MediaItem table.

  3. Register and map

    Call AddMedia<AppDbContext>() and app.MapMediaEndpoints().

  4. Upload and link

    UploadAsync returns the item; link to it at /_media/{uid}.

Quick start

Wire it up

Local disk is the default store; the MediaItem column mapping targets SQL Server.

The full setup guide lives in the documentation.

csharp
// Program.cs
builder.Services.AddMedia<AppDbContext>(o => o.MediaRoot = @"D:\Data\media");
app.MapMediaEndpoints();

// anywhere you accept a file
var item = await store.UploadAsync(file.OpenReadStream(), file.FileName, file.ContentType, folder: "covers");
var url = $"/_media/{item.Uid}";

Part of MindAttic

One piece of a bigger workshop

MindAttic.Storage is the family's media layer. Prose and IdeaCms store their uploads through it, and both reference the package with a Debug-only project reference to a sibling checkout, so local changes are picked up without repacking.

It was formerly MindAttic.Media; the API and public type names are unchanged, only the namespaces moved to MindAttic.Storage.

Status

Where it stands

Released 1.0

1.0 is out; the local-disk store is the supported path

Version 1.0.0 of both packages is published to the MindAttic NuGet feed and in use. With MindAttic's Azure resources retired, the remaining work is testing the local-disk DI wiring and documenting how consumers move off the frozen Azure backend.

Current milestone: MindAttic.Storage 1.x: the local-disk store complete, the Azure backend frozen.

Next step

Stop rebuilding upload plumbing

Guides, reference and design notes are in the searchable MindAttic documentation. The source, issues and history are on GitHub.