Files
pos-system/services/storage-service-net
Ho Ngoc Hai 964e33bee6 feat(storage): Implement multipart upload functionality and caching for file operations
- Added multipart upload methods to the IStorageProvider interface and implemented them in the MinioStorageProvider and AliyunOssStorageProvider classes.
- Integrated Redis caching for user quota management in ConfirmUploadCommandHandler and DeleteFileCommandHandler to ensure updated quota values.
- Enhanced GetUserQuotaQueryHandler to utilize cache-aside pattern for improved performance.
- Updated Dependency Injection to register Redis cache service and configured related settings.
- Introduced database schema changes to support multipart uploads and their parts.
2026-01-13 23:42:35 +07:00
..

Storage Service .NET / Dịch vụ Lưu trữ .NET

EN: Microservice for file storage management supporting MinIO and Aliyun OSS.
VI: Microservice quản lý lưu trữ file hỗ trợ MinIO và Aliyun OSS.

Features / Tính năng

  • Multi-provider storage: MinIO (S3-compatible) and Aliyun OSS
  • Provider switching: Switch providers via environment variable
  • File CRUD operations: Upload, download, delete, list files
  • Pre-signed URLs: Secure time-limited download/upload URLs
  • User quotas: Storage capacity and file count limits
  • Inter-service auth: JWT validation via IAM Service

Architecture / Kiến trúc

├── src/
│   ├── StorageService.API/           # Controllers, Commands, Queries
│   ├── StorageService.Domain/        # Entities, Repository interfaces
│   └── StorageService.Infrastructure/# Providers, DbContext, Repositories
└── tests/
    ├── StorageService.UnitTests/
    └── StorageService.FunctionalTests/

Quick Start / Bắt đầu nhanh

Prerequisites / Yêu cầu

  • .NET 10 SDK
  • Docker & Docker Compose
  • PostgreSQL (or Neon)
  • MinIO (or Aliyun OSS)

Run with Docker / Chạy với Docker

cd services/storage-service-net
docker-compose up -d

Access at: http://localhost:5002/swagger

Run locally / Chạy local

cd services/storage-service-net
dotnet run --project src/StorageService.API

Configuration / Cấu hình

Variable Description Default
Storage__Provider Provider: minio or aliyun minio
Storage__DefaultBucket Default bucket name storage
Storage__MinIO__Endpoint MinIO endpoint localhost:9000
Storage__MinIO__AccessKey MinIO access key -
Storage__MinIO__SecretKey MinIO secret key -
Storage__AliyunOSS__Endpoint OSS endpoint -
Storage__AliyunOSS__AccessKeyId OSS access key -
Storage__AliyunOSS__AccessKeySecret OSS secret key -
IamService__BaseUrl IAM Service URL http://localhost:5001

API Endpoints

Method Endpoint Description
POST /api/v1/files/upload Upload file
GET /api/v1/files List user files
GET /api/v1/files/{id} Get file by ID
GET /api/v1/files/{id}/download-url Get pre-signed download URL
DELETE /api/v1/files/{id} Delete file
GET /api/v1/quota Get user quota

Database Migrations / Migration Database

cd services/storage-service-net
dotnet ef migrations add InitialCreate --project src/StorageService.Infrastructure --startup-project src/StorageService.API
dotnet ef database update --project src/StorageService.Infrastructure --startup-project src/StorageService.API

Testing / Kiểm thử

# Unit tests
dotnet test tests/StorageService.UnitTests

# All tests
dotnet test

License

MIT