Sophia Lee
Digital Marketing
January 24, 2025
Introduction
In today's digital world, file storage and management is one of the fundamental requirements of every application. Choosing and managing between different storage solutions like AWS S3, MinIO, and local storage can be a complex process. In this article, we will examine a flexible bucket service developed with Node.js that supports multiple storage providers.
Project Overview
This bucket service is a comprehensive solution designed to meet the file management needs of modern web applications. The service supports three different storage types:
AWS S3: Cloud-based, scalable storage
MinIO: Open-source, S3-compatible object storage
Local Storage: For development and testing environments
Technical Architecture
Technology Stack
Database Model
The service works on two main models using PostgreSQL database:
Bucket Model
FileStore Model
Key Features
1. Multi-Provider Support
The service can dynamically switch between different storage providers based on the BUCKET_TYPE
parameter determined by the environment variable:
2. Secure File Upload
The service secures file upload operations using a JWT-based authorization system:
3. Automatic Bucket Management
Buckets are automatically checked and created when necessary:
API Endpoints
1. Health Check
Checks the service status and connection information.
Response:
2. File Upload
Supports multiple file upload operations (maximum 10 files).
Request Parameters:
userId
: User IDbuckets
: Authorization informationfiles
: Files to upload (multipart/form-data)
Response:
3. File Download
Secure file download operation. Provides temporary access using signed URLs.
Security Features
JWT-Based Authorization
The service performs user authentication and authorization using JSON Web Token:
Permission Controls
Granular permission control is performed for each operation:
Read: File read/download permission
Write: File write/upload permission
Signed URLs
File download operations are performed using temporary and secure signed URLs.
Docker Development Environment
The project includes ready Docker Compose configuration for MinIO:
Installation and Usage
1. Install Dependencies
2. Set Environment Variables
3. Start the Service
Advantages
1. Flexibility
Support for three different storage types
Easy provider switching
Environment-based configuration
2. Security
JWT-based authentication
Granular permission system
Secure access with signed URLs
3. Scalability
Multiple file uploads
Asynchronous operations
Database-based metadata management
4. Developer Friendly
RESTful API design
Comprehensive error handling
Docker support
Use Cases
E-commerce Platforms: Product images and documents
Content Management Systems: Media files
Enterprise Applications: Document archiving
SaaS Applications: User files
Future Enhancements
File Preview: PDF, image preview support
File Compression: Automatic compression features
CDN Integration: Faster file access
Bulk Operations: Bulk file operations
Audit Logging: Detailed operation logs
Conclusion
This bucket service offers a comprehensive and flexible solution that meets the file management needs of modern web applications. It provides great convenience to developers with its multi-provider support, secure API design, and easy integration features.
Thanks to its open-source nature and modular architecture, the project can be customized and extended according to different needs. It is an ideal file management solution especially for teams working in microservice architecture.