storage-server
v1.2.0
Published
File server with multiple storage backends
Readme
File Storage Server
A distributed file storage system built with NestJS that provides high availability and multi-storage backend support with automatic failover capabilities.
📋 Project Overview
This project is a robust file storage microservice designed for enterprise applications requiring reliable file management across multiple storage backends. It acts as an abstraction layer between your application and various storage systems (MinIO, FTP, local filesystem), providing unified APIs for file operations while ensuring high availability through intelligent failover mechanisms.
Key Use Cases:
- Hospital/Healthcare systems managing medical images and documents
- Multi-tenant applications requiring isolated storage buckets
- Systems requiring automatic failover for critical file storage
- Applications needing dynamic image resizing for web/mobile delivery
- Content delivery with format optimization (WebP, AVIF conversion)
⚡ Key Features
- Multi-Storage Support: Support for MinIO, FTP (FileZilla), and other storage systems
- High Availability: Automatic server failover when issues occur
- File Streaming: Support for video/audio streaming
- Image Processing: On-the-fly image resizing and format conversion
- Priority System: Configurable server priority system
- RESTful API: Complete API for upload, download, stream, and delete operations
- Swagger Documentation: Auto-generated API documentation
🗄 Database Schema
server Table
- id: Primary key
- server_name: Server name
- key_server: Server cluster identifier
- read_priority: Priority order (1 = highest)
- type_server: enum('minio', 'filezilla')
- config: JSON configuration for server connection
- is_active: Server active statusdata_path Table
- id: Primary key
- path: File path
- key_server: Foreign key to server
- original_filename: Original filename
- mime_type: File MIME type
- file_size: File size in bytes📚 API Documentation
Access Swagger documentation after starting the server: {server}/api/docs
Main APIs:
File Operations
POST /api/files/upload- Upload file with bufferGET /api/files/:id- Get file with optional image resize- Query params:
width,height,fit(cover|contain|fill|inside|outside),format(jpeg|png|webp|avif)
- Query params:
GET /api/files/buffer/:id- Get file buffer (base64) with optional resizeGET /api/files/info/*- Get file informationDELETE /api/files/:path- Delete file
Image Resize Examples:
GET /api/files/123?width=300&height=200&fit=cover
GET /api/files/123?width=500&format=webp
GET /api/files/buffer/123?width=800&height=600&format=jpegServer Management
GET /api/servers- List all serversGET /api/servers/active- List active serversPOST /api/servers/health-check/:keyServer- Check server healthPOST /api/servers/switch-priority- Switch server priority
🔧 Storage Configuration
MinIO
{
"endpoint": "localhost",
"port": 9000,
"accessKey": "minioadmin",
"secretKey": "minioadmin",
"useSSL": false,
"bucketName": "file-storage"
}FTP (FileZilla)
{
"host": "localhost",
"port": 21,
"user": "ftpuser",
"password": "ftppass"
}🛡 High Availability
The system automatically:
- Uses servers with
read_priority = 1andis_active = true - Automatically switches to the next priority server when the primary fails
- Provides manual failover via the
switch-priorityAPI
🖼 Image Processing
Built-in image processing capabilities using Sharp:
- Resize: Specify width and/or height
- Fit modes: cover, contain, fill, inside, outside
- Format conversion: JPEG, PNG, WebP, AVIF
- Quality control: Optimized compression settings
- Automatic detection: Only processes image MIME types
🔍 Monitoring
- Health check endpoints for each server
- Detailed logs for debugging
- Swagger UI for API testing
📝 Development
# Install dependencies
npm install
# Watch mode
npm run start:dev
# Run tests
npm run test
# Build for production
npm run build
# Run production
npm run start:prod📦 Dependencies
- NestJS - Backend framework
- Sharp - Image processing
- MinIO Client - Object storage
- FTP - File transfer protocol
- TypeORM - Database ORM
- Swagger - API documentation
