Skip to content

ack-solutions/nest-file-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

@ackplus/nest-file-storage

Nest Logo

A flexible and feature-rich file storage solution for NestJS applications

NPM Version Package License NPM Downloads

πŸ“¦ About

@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.

Key Features

  • πŸ“¦ 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

πŸ“¦ Installation

npm install @ackplus/nest-file-storage

For AWS S3:

npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presigner

For Azure Blob Storage:

npm install @azure/storage-blob

πŸš€ Quick Example

1. 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! πŸŽ‰

πŸ“š Documentation

Package Documentation

Example Application

See a complete working example:

  • Example App - Working implementation with file upload/download

πŸ› οΈ Local Development

This section is for contributors working on the package itself.

Setup

# 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 build

Project Structure

nest-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

Development Workflow

# 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 build

Watch Mode (Multi-Terminal)

For 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

Publishing

# 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

πŸ§ͺ Testing

# Package tests
pnpm -C packages/nest-file-storage test

# Example app tests
pnpm -C apps/example-app test

🎯 Use Cases

  • 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

🀝 Contributing

Contributions are welcome!

Quick steps:

  1. Fork the repo
  2. Create a branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Build and test (pnpm -C packages/nest-file-storage build)
  5. Commit changes (git commit -m 'Add amazing feature')
  6. Push to branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

πŸ“„ License

MIT License - see LICENSE

πŸ”— Links

🌟 Features by Storage Provider

Local Storage

  • βœ… File upload/download
  • βœ… File deletion
  • βœ… File copying
  • βœ… Get file path
  • βœ… Get public URL

AWS S3

  • βœ… File upload/download
  • βœ… File deletion
  • βœ… File copying
  • βœ… Get public URL
  • βœ… Generate signed URLs
  • βœ… CloudFront integration

Azure Blob Storage

  • βœ… File upload/download
  • βœ… File deletion
  • βœ… File copying
  • βœ… Get public URL
  • βœ… Container management

Made with ❀️ for the NestJS community

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published