npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@uploadflow/nestjs

v0.1.0

Published

NestJS dynamic module for the uploadflow file-upload pipeline (decorators, interceptors, presign controller)

Downloads

24

Readme

@uploadflow/nestjs

NestJS dynamic module for the uploadflow file-upload pipeline: pluggable storage (Azure Blob with real SAS / AWS S3 / local / custom), magic-byte validation, presigned direct-to-storage uploads, and record-linked uploads — all behind decorators.

npm i @uploadflow/nestjs @uploadflow/core
# storage driver (optional peer of core) — install the one you use:
npm i @azure/storage-blob
# or: npm i @aws-sdk/client-s3 @aws-sdk/lib-storage @aws-sdk/s3-request-presigner
# linked uploads on Mongo (optional): npm i @uploadflow/mongoose

Peer deps: @nestjs/common, @nestjs/core, @nestjs/platform-express, reflect-metadata, rxjs.

1. Register UploadModule

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { UploadModule } from '@uploadflow/nestjs';

@Module({
  imports: [
    UploadModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (cfg: ConfigService) => ({
        storage: {
          driver: cfg.get('STORAGE_PROVIDER') === 's3' ? 's3' : 'azure',
          azure: {
            account: cfg.get('AZURE_STORAGE_ACCOUNT_NAME'),
            accountKey: cfg.get('AZURE_STORAGE_ACCOUNT_KEY'),
            container: cfg.get('AZURE_STORAGE_CONTAINER_NAME'),
          },
          s3: {
            region: cfg.get('S3_REGION'),
            bucket: cfg.get('S3_BUCKET'),
            accessKeyId: cfg.get('S3_AWS_ACCESS_KEY'),
            secretAccessKey: cfg.get('S3_AWS_SECRET_KEY'),
          },
        },
        validation: { maxFileSize: '50mb', magicBytes: true },
        urlMode: 'signed',      // 'signed' (private, short-lived URLs) | 'public'
        controller: true,       // mount POST /uploads/presign + /uploads/confirm
      }),
    }),
  ],
})
export class AppModule {}

forRoot(options) exists for static config. The module is global by default, so decorators work everywhere without re-importing.

2. Direct upload — @UploadFile

import { Controller, Post } from '@nestjs/common';
import { UploadFile, UploadedFileMeta } from '@uploadflow/nestjs';
import { StoredObject } from '@uploadflow/core';

@Controller('users')
export class UserController {
  @Post('avatar')
  @UploadFile({ field: 'avatar', allow: ['image/png', 'image/jpeg'], maxFileSize: '5mb' })
  uploadAvatar(@UploadedFileMeta() file: StoredObject) {
    return file; // { key, url, size, mime, originalName } — already stored
  }
}

Options: { field, multiple?, maxCount?, allow?, maxFileSize?, category? }. With multiple: true, @UploadedFileMeta() returns StoredObject[].

3. Linked upload — @LinkedUpload + @WithAttachments

Auto-links a file to the record your handler returns; injects attachments back into the response. Ordering guarantees no orphan blob if anything fails.

import { Body, Controller, Delete, Get, Param, Post } from '@nestjs/common';
import { LinkedUpload, WithAttachments } from '@uploadflow/nestjs';

@Controller('media')
export class MediaController {
  @Post()
  @LinkedUpload({ fields: ['mediaFile'], module: 'MEDIA', recordIdFrom: (r) => r._id })
  create(@Body() dto: CreateMediaDto) {
    return this.service.create(dto); // resolve to a record with _id; response gets `attachments`
  }

  @Get(':id')
  @WithAttachments({ module: 'MEDIA' })
  getById(@Param('id') id: string) {
    return this.service.findById(id); // response gets `attachments` with resolved URLs
  }

  @Delete(':id')
  @LinkedUpload({ fields: ['mediaFile'], module: 'MEDIA' })
  remove(@Param('id') id: string) {
    return this.service.remove(id); // attachments unlinked
  }
}

Linked/read decorators need an attachmentStore in module options. Zero-setup with Mongoose:

import { MongooseAttachmentStore } from '@uploadflow/mongoose';
// in useFactory (inject the mongoose Connection, e.g. getConnectionToken()):
attachmentStore: MongooseAttachmentStore.forRoot({ connection, collection: 'attachments' })

Or supply any class/instance implementing AttachmentStore from @uploadflow/core.

@LinkedUpload options: { fields, module?, allow?, maxFileSize?, recordIdFrom?, createdByFrom? }. recordIdFrom defaults to r._id ?? r.id ?? r.data._id. For PUT/PATCH, pass attachmentIds in the body to replace existing attachments.

4. Presigned upload (with controller: true)

| Route | Body | Returns | |---|---|---| | POST /uploads/presign | { filename, contentType, size?, category? } | { uploadUrl, key, method, headers, expiresAt } | | POST /uploads/confirm | { key, originalName?, mimeType? } | StoredObject |

// client
const { uploadUrl, key, headers } = await api.post('/uploads/presign',
  { filename: file.name, contentType: file.type }).then(r => r.data);
await fetch(uploadUrl, { method: 'PUT', body: file, headers });   // straight to storage
const meta = await api.post('/uploads/confirm', { key }).then(r => r.data);

Prefer to own the routes? Inject PresignService and call getUploadUrl / confirm.

Errors

Validation failures are UploadflowError and are auto-mapped to HTTP (400 invalid type / unverified content, 413 too large, 404 not found).

Full docs, config reference, custom adapters, and aggregation reads: https://github.com/OWNER/uploadflow#readme

MIT