Aviary

Media

The media library for NestJS, on top of @nestjs/storage — the spatie feel for files. Entity attachments, image conversions, resumable and direct uploads, and a /media console, all wired into the ecosystem's diagnostics, codegen, and React glue points.

@dudousxd/nestjs-media brings the spatie/media-library experience to NestJS. NestJS's own @nestjs/storage gives you the disks (local, S3 and S3-compatible, in-memory), signed URLs, serveFile() and streamed uploads; media builds on those disks what they don't cover: file-to-entity attachments in collections, image conversions, resumable (tus) and presigned-multipart uploads, and a /media console.

Two layers, one package

Layer 1 — Storage: @nestjs/storage's disks (put / get / url / signedUrl / delete). Not part of media: configure it with StorageModule and use it directly for files that aren't media.

Layer 2 — Media-library: attach files to your entities in named collections, with image conversions, uploads and attachments — written through those disks.

The problem it solves

Handling user files in a backend is deceptively fiddly, and the pain shows up in three places.

Storage portability. You start on the local filesystem in dev and move to S3 in production. @nestjs/storage already gives you one StorageDisk API for both; media writes everything through it, so the media library follows whatever disks you configure.

Uploads that survive reality. A 400 MB video upload that dies at 90% because the user's wifi blinked is a terrible experience — and proxying every byte through your Node process doesn't scale. media ships both answers: a resumable tus server for the proxy path, and presigned S3 multipart for the direct path, with an uploadMode that picks the right one per disk and lets you override it per call.

Files that belong to things. "This post has a gallery of images, each with a thumbnail and an OG variant; the avatar is single-file and replaces on re-upload." That's not raw storage — it's a media library. media models it spatie-style: entities have collections, collections have rules and conversions, and the bytes-plus-metadata live in a media table managed by your ORM.

Mental model

        your code
            │
   media.library            Storage / @InjectDisk()
   (nestjs-media)           (@nestjs/storage)
   attach / list /          put / get / url /
   url / conversions        signedUrl / delete
            │                    │
       MediaStore           StorageDisk
   (typeorm/mikro/          (LocalDisk / S3Disk /
    drizzle/prisma)          InMemoryDisk)

The media-library writes bytes through a @nestjs/storage disk and records metadata through a store. Swap either side without touching the other.

What you get

  • Disks: whatever @nestjs/storage is configured with. For native S3 multipart (resumable and direct uploads) and folder listing, the -disk-s3 side-car adds what S3Disk keeps private; -testing checks any disk against what media relies on.
  • Resumable uploads: the proxy path is a real tus 1.0.0 server (chunked, resumable through a dropped connection); the direct path uses presigned S3 multipart. An overridable uploadMode (auto | proxy | direct) decides which, resolved global → per-disk → per-call.
  • Media-library: spatie-style collections (single-file or multi), ordering, MIME validation, custom properties, and attach / list / delete / url.
  • Image conversions: a pluggable ImageProcessor (sharp by default), generated lazily on first access (and cached) or eagerly on upload.
  • Four ORM stores: TypeORM, MikroORM, Drizzle, Prisma — POJO adapters that all satisfy the same MediaStore contract, with non-destructive auto-schema where the ORM allows.
  • Ecosystem glue points: aviary:media:* diagnostics channels, a Telescope watcher, a codegen-emitted typed client, and a React useMediaUpload hook + <MediaUploader/>.

When (and when not) to use it

Reach for media when files are a first-class part of your domain — user uploads, attachments, galleries, documents — and you want one consistent API across environments plus a browser upload story that doesn't fall over on large files.

You don't need media for every file. A generated report, a cache, a file another library reads: use @nestjs/storage directly (docs).

How it fits the ecosystem

media is plugged into the same four glue points every @dudousxd/nestjs-* library shares — it emits to node:diagnostics_channel channels that Telescope consumes, contributes a typed client through Codegen, and ships a -react family package. See Concepts → Diagnostics & the glue points for the wiring.

Continue to Getting Started.

On this page