Aviary
Packages

@dudousxd/nestjs-media-disk-s3

s3Multipart() — the native multipart and folder listing that @nestjs/storage's S3Disk keeps private, for resumable and direct uploads and the dashboard.

The files live on @nestjs/storage's S3Disk (Amazon S3, Cloudflare R2, MinIO, Backblaze B2, …). S3Disk uses multipart uploads internally for large put()s, but exposes no part-level API and lists flat only. This package adds exactly that, as a side-car for one disk:

import { S3Disk, StorageModule, type S3DiskOptions } from '@nestjs/storage';
import { s3Multipart } from '@dudousxd/nestjs-media-disk-s3';

const s3: S3DiskOptions = {
  bucket: 'app-uploads',
  region: 'auto',
  endpoint: process.env.R2_ENDPOINT,
  credentials: { accessKeyId, secretAccessKey },
  prefix: 'tenants/t1/',
};

StorageModule.forRoot({ disks: { s3: new S3Disk(s3) } });
MediaModule.forRoot({ multipart: { s3: s3Multipart(s3) }, /* uploadSessions, direct, ... */ });

Same options, same objects

Pass the side-car the same options object as the disk. It applies the same prefix, endpoint and addressing style (forcePathStyle, IP endpoints, bucket names that aren't valid host names), so a key means the same object on both. Options only S3Disk uses (retries, timeouts, part size, publicUrl) are ignored.

What it adds

interface S3Multipart extends MultipartUploadDriver {
  createMultipartUpload(key, { contentType?, cacheControl?, metadata? }?): Promise<{ uploadId }>;
  uploadPart(key, uploadId, partNumber, body: Buffer): Promise<{ partNumber, etag }>; // proxy path
  presignUploadPart(key, uploadId, partNumber, expiresInSeconds): Promise<string>;   // direct path
  completeMultipartUpload(key, uploadId, parts): Promise<void>;
  abortMultipartUpload(key, uploadId): Promise<void>;      // an upload already gone is not an error
  listFolders(prefix, { cursor?, limit? }?): Promise<FolderListing>; // ListObjectsV2 + Delimiter '/'
}

You rarely call these yourself: ResumableUploadManager (tus and parallel parts), DirectUploadManager (presigned parts) and the dashboard's folder listing use them. listFolders() returns 50 entries per page unless you pass limit (at most 1000; anything but a positive integer is a RangeError), the same page size as the folded listing (see Folders). Keys go through @nestjs/storage's key rule first, so no object is ever created at a key the disk can't read back. Server-side encryption options (serverSideEncryption, kmsKeyId) apply to multipart uploads too.

Like S3Disk, it runs over fetch with Signature Version 4 on node:crypto — no AWS SDK. Credentials: the options' credentials (an object, or a function called per request), else AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY / AWS_SESSION_TOKEN. Transient failures (429, 5xx, network) are retried twice. A failed request throws S3MultipartError with S3's code.

Verified against MinIO

describeMediaDiskConformance from -testing runs against S3Disk on a real MinIO with this side-car (parts uploaded out of order, abort, presign, listFolders agreeing with the folded flat listing), plus resumable uploads end to end.

Peer dependencies

@nestjs/storage (>=0.0.5 <0.1.0) and @dudousxd/nestjs-media-core.

On this page