A flexible and feature-rich file storage solution for NestJS applications
@ackplus/nest-file-storage is a comprehensive file storage solution for NestJS applications that supports multiple storage providers including Local Storage, AWS S3, and Azure Blob Storage. Upload, download, delete, and manage files with ease.
- π¦ Multiple Storage Providers - Local, AWS S3, and Azure Blob Storage
- π Easy Switching - Switch between providers with minimal configuration
- π― NestJS Integration - Seamless integration with decorators and interceptors
- π File Operations - Upload, download, delete, copy files
- π Signed URLs - Generate presigned URLs for secure access (S3)
- π¨ Customizable - Custom file naming and directory structure
- β Type-Safe - Full TypeScript support
npm install @ackplus/nest-file-storageFor AWS S3:
npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presignerFor Azure Blob Storage:
npm install @azure/storage-blob1. Configure Module:
// app.module.ts
import { Module } from '@nestjs/common';
import { NestFileStorageModule, FileStorageEnum } from '@ackplus/nest-file-storage';
@Module({
imports: [
NestFileStorageModule.forRoot({
storage: FileStorageEnum.LOCAL,
localConfig: {
rootPath: './uploads',
baseUrl: 'http://localhost:3000/uploads',
},
}),
],
})
export class AppModule {}2. Upload Files in Controller:
// upload.controller.ts
import { Controller, Post, UseInterceptors, Body } from '@nestjs/common';
import { FileStorageInterceptor } from '@ackplus/nest-file-storage';
@Controller('upload')
export class UploadController {
@Post('single')
@UseInterceptors(FileStorageInterceptor('file'))
uploadSingle(@Body() body: any) {
return {
message: 'File uploaded successfully',
fileKey: body.file, // File key automatically added
};
}
}3. Manage Files with Service:
// file.service.ts
import { Injectable } from '@nestjs/common';
import { FileStorageService } from '@ackplus/nest-file-storage';
@Injectable()
export class FileService {
async getFile(key: string): Promise<Buffer> {
const storage = await FileStorageService.getStorage();
return await storage.getFile(key);
}
async deleteFile(key: string): Promise<void> {
const storage = await FileStorageService.getStorage();
await storage.deleteFile(key);
}
}Done! π
- π Complete Documentation - Full guide with all features
- π Examples - 10 detailed examples covering all use cases
See a complete working example:
- Example App - Working implementation with file upload/download
This section is for contributors working on the package itself.
# Clone repository
git clone https://github.com/ack-solutions/nest-file-storage.git
cd nest-file-storage
# Install dependencies
pnpm install
# Build package
pnpm -C packages/nest-file-storage buildnest-file-storage/
βββ packages/
β βββ nest-file-storage/ # π¦ Main package
β βββ src/ # Source code
β β βββ lib/
β β β βββ storage/ # Storage implementations
β β β βββ interceptor/ # File upload interceptor
β β β βββ file-storage.service.ts
β β β βββ nest-file-storage.module.ts
β β β βββ types.ts
β β βββ index.ts
β βββ dist/ # Compiled output
β βββ examples/ # 10 example files
β βββ README.md # Package documentation
βββ apps/
β βββ example-app/ # π§ͺ Example application
β βββ src/ # Working example
βββ scripts/
β βββ publish.js # Publishing script
βββ package.json # Root workspace
# Build package
pnpm -C packages/nest-file-storage build
# Run example app (if implemented)
cd apps/example-app
pnpm start:dev
# Make changes and test
pnpm -C packages/nest-file-storage buildFor active development, run these in separate terminals:
# Terminal 1: Build watch
pnpm -C packages/nest-file-storage build --watch
# Terminal 2: App development
pnpm -C apps/example-app start:dev# Interactive version bump and publish
npm run publish
# The script will:
# 1. Ask for version type (patch/minor/major)
# 2. Build package
# 3. Update version
# 4. Publish to npm# Package tests
pnpm -C packages/nest-file-storage test
# Example app tests
pnpm -C apps/example-app test- User Avatars - Upload and manage user profile pictures
- Document Management - Handle document uploads and downloads
- Image Gallery - Store and serve images
- File Sharing - Build file sharing features
- Media Storage - Store videos, audio, and other media
- Backup Systems - Store backups across different providers
Contributions are welcome!
Quick steps:
- Fork the repo
- Create a branch (
git checkout -b feature/amazing-feature) - Make your changes
- Build and test (
pnpm -C packages/nest-file-storage build) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see LICENSE
- β File upload/download
- β File deletion
- β File copying
- β Get file path
- β Get public URL
- β File upload/download
- β File deletion
- β File copying
- β Get public URL
- β Generate signed URLs
- β CloudFront integration
- β File upload/download
- β File deletion
- β File copying
- β Get public URL
- β Container management
Made with β€οΈ for the NestJS community