File Service
File Service is responsible for handling file upload, storage, retrieval, and processing within the system. It provides a centralized and secure way to manage files and images across the platform.
Core Responsibilities
- Accepting files uploaded by users
- Validating files based on predefined rules
- Storing files in a filesystem or object storage
- Providing file and image download capabilities
- Dynamically processing and resizing images
- Migrating files between different storage systems
- Logging errors and critical operations
File Upload Capabilities
File Service supports multiple upload methods:
- File uploads through forms
- File uploads based on predefined categories
- File uploads using Base64-encoded content
During the upload process, the following validations are applied:
- File size must not exceed the configured limit
- File extension must be within the allowed formats
- File must belong to a valid category
- File paths must not contain unsafe or invalid sequences
File Storage Mechanism
Files can be stored using different strategies:
- Local server filesystem storage
- Object storage (such as MinIO)
During storage:
- File metadata is persisted in the database
- Storage location and storage type are recorded
- File size, format, category, and timestamps are saved
- Operations are executed within transactional boundaries
File Download and Access
File Service provides file access in different modes:
- Regular files are returned as downloadable attachments
- Images can be served inline for browser rendering
- Appropriate content type and filename headers are set automatically
- Errors are returned if files are missing or inaccessible
Image Processing
The service offers advanced image handling features:
- Resizing images by explicit width and height
- Scaling images by percentage
- Proportional resizing based on width or height
- Automatic generation of resized versions when not available
- Caching resized images for future requests
Migration Capabilities
File Service supports file migration between storage systems:
- Migrating files from local storage to object storage
- Migrating files from object storage back to local storage
- Batch processing with configurable limits
- Returning migration results in a structured format
Security and Error Handling
- Invalid requests return descriptive error responses
- Missing files result in appropriate error messages
- Storage and retrieval failures are properly logged
- Critical errors are published to monitoring and logging systems
Summary
File Service is a comprehensive solution for file management, covering upload, storage, processing, retrieval, and migration. It is designed to be secure, scalable, and extensible to support various file-related use cases across the platform.