Files
pos-system/services/storage-service-net
..

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

Files

Method Endpoint Description
POST /api/v1/files/upload Upload file via backend
GET /api/v1/files List user files with pagination
GET /api/v1/files/{id} Get file metadata by ID
GET /api/v1/files/{id}/download-url Get download URL (presigned for private)
DELETE /api/v1/files/{id} Soft delete file
Method Endpoint Description
POST /api/v1/storage/sign-upload Get pre-signed PUT URL
POST /api/v1/storage/confirm-upload Confirm upload and save metadata

File Sharing

Method Endpoint Description
POST /api/v1/files/{id}/share Create share link for file
GET /api/v1/files/shared/{token} Access file via share token
DELETE /api/v1/files/{id}/share Revoke share link

Quota

Method Endpoint Description
GET /api/v1/quota Get current user quota
GET /api/v1/quota/me Get quota for authenticated user

Note: For private/shared files, download-url returns a pre-signed URL with AWS Signature V4. See docs/en/README.md for details.

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