medOS File Storage
Internal scope:
ever-filestore· Port: 8083 · File upload/download with pluggable IPFS or S3 backends and content-hash verification.
The File Storage service owns binary object handling for the whole platform — uploads, downloads, and the indirection layer that lets a deployment choose where blobs actually live. The same upload API works whether the configured backend is AWS S3 (managed cloud) or IPFS / IPFS Cluster (decentralized and on-premise). Every object is addressed by a content hash, so callers store and retrieve a stable identifier rather than a backend-specific path, and integrity can be re-verified on read.
Responsibilities
- Upload & download — accept single and multi-file uploads, stream files back on request, and serve both authenticated and designated public read paths.
- Backend abstraction — route storage operations to S3 or IPFS based on the
FILESTORE_BACKENDconfiguration, keeping the caller-facing contract identical. - Content-hash addressing — return a content hash as the canonical file id, so retrieval and integrity verification key off the content itself.
- IPFS lifecycle — pin and unpin content, query node/cluster version, and resolve metadata by hash against both a local node and an IPFS Cluster.
- Document upload helper — a higher-level document-upload path that wraps a raw file store and returns the resulting file id.
- Access control — JWT strategy, token guard, and an auth service that gate non-public file operations.
- Cache hygiene — service-event mixins that listen for clean-up signals and evict stale cached file entries.
Major modules
| Module | Purpose |
|---|---|
modules/s3 | AWS S3 backend — s3.service.ts for object operations plus s3.config.ts for bucket/region configuration. |
modules/ipfs | IPFS backend — service, repository, controller mixin, and DTOs covering upload, get-file, pin add/remove, info-by-hash, and the IPFS Cluster equivalents. |
modules/auth | Access control — JWT strategy, token guard, and auth service/controller protecting file routes. |
serviceEvents | Cache-clean mixins (fileStore.cache.clean and fileStoreCacheCleanEvents) that react to platform events and invalidate cached entries. |
filestoreService.ts | Service entry point binding the modules into the Moleculer/NestJS runtime. |
Backend selection & configuration
The active backend is chosen at deploy time. Storage code paths are otherwise identical, which is what lets the cloud and on-premise topologies share one image.
| Config flag | Purpose |
|---|---|
FILESTORE_BACKEND | Selects the active backend (S3 vs. IPFS). |
SERVICE_FILESTORE_PORT | Service listen port (defaults to 8083). |
IPFS_HOST / IPFS_PORT / IPFS_PROTOCOL | Connection details for the local IPFS node. |
IPFS_CLUSTER_HOST / IPFS_CLUSTER_PORT / IPFS_CLUSTER_PROTOCOL | Connection details for the IPFS Cluster (replicated pinning). |
All connection values are environment-parameterized — no backend endpoint is hardcoded — so the same build runs against managed cloud storage or a self-hosted IPFS fabric.
Upload & retrieval flow
Caller (service / frontend)
│ upload file(s)
▼
┌────────────────────────────┐
│ ever-filestore │
│ ┌──────────────────────┐ │
│ │ JWT guard / auth │ │ non-public routes
│ └──────────┬───────────┘ │
│ ▼ │
│ FILESTORE_BACKEND ? │
│ ┌───────┴───────┐ │
│ ▼ ▼ │
│ ┌─────┐ ┌────────┐ │
│ │ S3 │ │ IPFS │ │ pin → (IPFS Cluster)
│ └──┬──┘ └───┬────┘ │
└─────┼───────────────┼──────┘
│ content hash returned as fileId
▼ ▼
stored object addressable by hash
│
▼
Caller stores fileId → later get-file / get-public-file by hash
On retrieval the service resolves the object by its hash and streams it back with the stored content type; because the id is the content hash, the same identifier doubles as the integrity check. A separate public-file path serves designated content without an auth token, while all other operations pass through the JWT guard.
Integration notes
- Other backend services (for example clinical, diagnostic, and printing flows) store and reference documents by the file id this service returns, keeping blobs out of the primary databases.
- The IPFS path makes File Storage the natural data plane for immutable, content-addressed artifacts in on-premise and edge deployments; secrets and live state are handled elsewhere.
Related catalog items
SYS-7— File Storage (S3)INT-12— IPFS Document StorageST-8— File Storage Encryption