Skip to main content

Storage Service API

The Storage Service provides robust file storage, versioning, and retrieval capabilities across your organization’s infrastructure. This service abstracts away the underlying storage vendor implementation, allowing seamless interaction with files regardless of where they’re physically stored.

Base URL

All endpoints are prefixed with /api/v1/document

Authentication

All endpoints require authentication via Bearer token:
Internal endpoints use scoped token authentication for service-to-service communication with specific scopes:
  • STORAGE_TOKEN - For storage operations
  • FETCH_CONFIG - For configuration updates

Architecture Overview

The Storage Service is built on a Node.js backend with MongoDB for metadata persistence. It provides a flexible storage interface that supports three storage vendor backends:
  1. Amazon S3 - For cloud-based storage on AWS
  2. Azure Blob Storage - For cloud-based storage on Microsoft Azure
  3. Local Storage - For on-premises file storage
The service integrates with other components such as:
  • Configuration Manager - Manages storage configuration settings stored in etcd
  • IAM Service - Handles user authentication and authorization
  • Key-Value Store - Provides access to configuration data from etcd

Storage Configuration

Storage configuration is maintained in etcd under the /services/storage path. The configuration determines which storage vendor is active and the credentials needed to access it. The service dynamically loads this configuration at runtime and can switch between storage vendors without restarting.

Authentication Modes

The Storage Service offers two authentication modes:
  1. User Authentication - Uses standard user JWT tokens for operations performed by end users
  2. Service Authentication - Uses scoped tokens with specific permissions for service-to-service communication

Data Models

Document

The Document model represents metadata about files stored in the system, including:
  • Basic information (name, path, size, MIME type)
  • Versioning metadata and history
  • Storage location details
  • Permissions and ownership
  • Custom metadata

Version History

Each versioned document maintains a complete history of changes, including:
  • Previous versions of the document
  • Metadata for each version (size, creation time, creator)
  • Storage locations for each version
  • Version notes and labels

API Endpoints

Core document operations including upload, retrieval, and deletion.
Upload a new document to the storage service.
Endpoint: POST /api/v1/document/uploadRequest Body Parameters:File Size Limits:
  • User endpoints: 1GB (1024 * 1024 * 1000 bytes)
  • Internal endpoints: 100MB (1024 * 1024 * 100 bytes)
Direct Upload Threshold: 0MB (all files trigger direct upload for S3/Azure for large files)Validation Rules:
  • Document name cannot contain extensions or forward slashes
  • File must have a valid extension with supported MIME type
  • File buffer is required in multipart form data
Supported MIME Types: Extensive list including documents (PDF, Office), images (JPEG, PNG, SVG), archives (ZIP, RAR), and many others.
Internal endpoint for service-to-service document uploads.
Endpoint: POST /api/v1/document/internal/uploadAuthentication: Requires scoped token with STORAGE_TOKEN scope.Request Body: Same structure as public upload endpoint.File Size Limit: 100MB for internal uploads.
Create a document placeholder for future direct uploads.
Endpoint: POST /api/v1/document/placeholderRequest Body Parameters:
Validation:
  • Document name cannot contain extensions or forward slashes
  • Extension must be provided separately
Internal endpoint for creating document placeholders.
Endpoint: POST /api/v1/document/internal/placeholderAuthentication: Requires scoped token with STORAGE_TOKEN scope.Request Body: Same structure as public placeholder endpoint.
Retrieve document metadata by ID.
Endpoint: GET /api/v1/document/:documentIdPath Parameters:
  • documentId: MongoDB ObjectId (24-character hex string)
Request Headers:
  • Authorization: Bearer token (required)
Request Body: Contains fileBuffer field for validation (per DocumentIdParams schema)
Internal endpoint for retrieving document metadata.
Endpoint: GET /api/v1/document/internal/:documentIdAuthentication: Requires scoped token with STORAGE_TOKEN scope.
Mark a document as deleted (soft delete).
Endpoint: DELETE /api/v1/document/:documentId/Path Parameters:
  • documentId: MongoDB ObjectId (24-character hex string)
Note: The endpoint includes a trailing slash in the route definition.
Internal endpoint for deleting documents.
Endpoint: DELETE /api/v1/document/internal/:documentId/Authentication: Requires scoped token with STORAGE_TOKEN scope.Query Parameters:
  • hard (optional): true removes the document instead of marking it deleted. Its stored files are removed first; if that fails, the failure is logged and the document is removed anyway.
Removes a document for good: every stored copy of its file (the current file and each version), then its metadata. PipesHub calls this when the record that owned the document is deleted, such as a file uploaded to a collection.
Endpoint: DELETE /api/v1/document/internal/:documentId/purgeAuthentication: Requires scoped token with STORAGE_TOKEN scope.Path Parameters:
  • documentId: MongoDB ObjectId (24-character hex string)
Removes the processed version of a record that indexing stored: the record_{virtualRecordId} and metadata_{virtualRecordId} documents, wherever they are filed (under the record’s folder path, or under records/{virtualRecordId} for older records), with their files. Records with identical content share one virtual record id, so PipesHub calls this only once no record uses it.
Endpoint: DELETE /api/v1/document/internal/records/:virtualRecordId/purgeAuthentication: Requires scoped token with STORAGE_TOKEN scope.Path Parameters:
  • virtualRecordId: 1 to 128 letters, digits, - and _. It is matched against exact document names and the exact records/{virtualRecordId} path, never as a prefix.
Operations for downloading and accessing document content.
Get a signed URL to download a document or stream it for local storage.
Endpoint: GET /api/v1/document/:documentId/downloadPath Parameters:
  • documentId: MongoDB ObjectId (24-character hex string)
Query Parameters:Validation:
  • Version is transformed from string to number and must be greater than 0 if provided
  • expirationTimeInSeconds is transformed from string to number and must be greater than 0 if provided
  • Version must exist in document’s version history
  • Only versioned documents can specify version parameter
  • Storage vendor must match current configuration
Internal endpoint for downloading documents.
Endpoint: GET /api/v1/document/internal/:documentId/downloadAuthentication: Requires scoped token with STORAGE_TOKEN scope.Query Parameters: Same as public download endpoint.
Get the document’s content as a buffer.
Endpoint: GET /api/v1/document/:documentId/bufferPath Parameters:
  • documentId: MongoDB ObjectId (24-character hex string)
Query Parameters:Validation:
  • Version is transformed from string to number via .pipe(z.number().min(0).optional())
  • Version must exist if specified
  • Version cannot exceed available version history length
Internal endpoint for retrieving document buffers.
Endpoint: GET /api/v1/document/internal/:documentId/bufferAuthentication: Requires scoped token with STORAGE_TOKEN scope.Query Parameters: Same as public buffer endpoint.
Update a document’s content.
Endpoint: PUT /api/v1/document/:documentId/bufferPath Parameters:
  • documentId: MongoDB ObjectId (24-character hex string)
Request Body Parameters:
  • file: File to upload (multipart/form-data with field name ‘file’)
File Size Limit: 100MB (1024 * 1024 * 100 bytes)Validation: Uses DocumentIdParams schema which includes fileBuffer in bodyBehavior:
  • Updates the document content in storage
  • Increments mutation count
  • Updates document size metadata
Internal endpoint for updating document buffers.
Endpoint: PUT /api/v1/document/internal/:documentId/bufferAuthentication: Requires scoped token with STORAGE_TOKEN scope.Request Body: Same as public buffer update endpoint.
Version control operations for document lifecycle management.
Upload a new version of an existing document.
Endpoint: POST /api/v1/document/:documentId/uploadNextVersionPath Parameters:
  • documentId: MongoDB ObjectId (24-character hex string)
Request Body Parameters:File Size Limit: 100MB (1024 * 1024 * 100 bytes)Validation:
  • Document must support versioning (isVersionedFile: true)
  • File extension must match existing document extension
  • Document existence and access verification
Behavior:
  • Checks if current document differs from last version
  • If changed, creates version entry for current state with currentVersionNote
  • Uploads new version with nextVersionNote
  • Updates current document content
  • Increments mutation count
Internal endpoint for uploading next version.
Endpoint: POST /api/v1/document/internal/:documentId/uploadNextVersionAuthentication: Requires scoped token with STORAGE_TOKEN scope.Request Body: Same structure as public upload next version endpoint.
Restore a document to a previous version.
Endpoint: POST /api/v1/document/:documentId/rollBackPath Parameters:
  • documentId: MongoDB ObjectId (24-character hex string)
Query Parameters:Request Body Parameters:Validation:
  • Uses RollBackToPreviousVersionSchema which extends GetBufferSchema
  • Version comes from query parameter (inherited from GetBufferSchema)
  • Note comes from request body
  • Document must support versioning
  • Target version must exist and be less than current version count
Note: There appears to be a discrepancy between the validator schema (which expects version in query) and the controller implementation (which reads version from body). The schema specification is documented here.
Internal endpoint for rolling back document versions.
Endpoint: POST /api/v1/document/internal/:documentId/rollBackAuthentication: Requires scoped token with STORAGE_TOKEN scope.Request Body: Same structure as public rollback endpoint.
Direct upload capabilities and utility functions.
Generate a presigned URL for directly uploading to storage.
Endpoint: POST /api/v1/document/:documentId/directUploadPath Parameters:
  • documentId: MongoDB ObjectId (24-character hex string)
Request Body: Empty object (per DirectUploadSchema)Use Case: For large files that need to be uploaded directly to storage vendor without going through the API server.Validation:
  • Document and document path must exist
  • Storage vendor configuration must be valid
  • Uses DirectUploadSchema validation
Internal endpoint for generating direct upload URLs.
Endpoint: POST /api/v1/document/internal/:documentId/directUploadAuthentication: Requires scoped token with STORAGE_TOKEN scope.
Check if a document has been modified since its last version.
Endpoint: GET /api/v1/document/:documentId/isModifiedPath Parameters:
  • documentId: MongoDB ObjectId (24-character hex string)
Validation: Uses DocumentIdParams schemaBehavior:
  • Compares current document buffer with latest version in history (or version 0)
  • Returns boolean indicating modification status
  • Uses buffer comparison for accurate change detection
Internal endpoint for checking document modification status.
Endpoint: GET /api/v1/document/internal/:documentId/isModifiedAuthentication: Requires scoped token with STORAGE_TOKEN scope.
Internal configuration management endpoints for service administration.
Internal endpoint for updating application configuration.
Endpoint: POST /api/v1/document/updateAppConfigAuthentication: Requires scoped token with FETCH_CONFIG scope.Behavior:
  • Reloads application configuration from configuration manager
  • Updates storage configuration in dependency injection container
  • Recreates storage controller with new configuration
  • Allows dynamic reconfiguration without service restart

Schema Definitions

Supported MIME Types

The storage service supports an extensive list of MIME types including:
  • PDF: application/pdf
  • Microsoft Office: Word (.docx, .doc), Excel (.xlsx, .xls), PowerPoint (.pptx, .ppt)
  • OpenDocument: .odt, .ods, .odp
  • Text: .txt, .rtf, .csv, .md, .mdx
  • Web: .html, .css, .js, .json, .xml
  • eBooks: .epub
  • Google Workspace: .gdoc, .gsheet, .gslides, .gdraw

Storage Provider Implementation

The Storage Service uses an adapter pattern to abstract the underlying storage provider implementation.
Features:
  • Direct file uploads/downloads via AWS SDK
  • Signed URLs with configurable expiration (default: 1 hour)
  • Multipart uploads for large files
  • Object versioning support
  • Comprehensive error handling with specific S3 error types
Configuration:
URL Structure:
Error Handling:
  • StorageConfigurationError - Missing credentials
  • StorageUploadError - Upload failures
  • StorageDownloadError - Download failures
  • PresignedUrlError - URL generation failures
  • MultipartUploadError - Multipart operation failures

File Size Limits & Direct Upload

Public Endpoints:
  • Upload: 1GB (1024 * 1024 * 1000 bytes)
  • Buffer operations: 100MB (1024 * 1024 * 100 bytes)
Internal Endpoints:
  • All operations: 100MB (1024 * 1024 * 100 bytes)
Direct Upload Threshold:
  • Set via maxFileSizeForPipesHubService constant
  • Currently configured to 0MB (all files trigger direct upload evaluation)
  • Applied only to S3 and Azure Blob storage
  • Local storage always uses direct API upload

Error Handling

All endpoints return structured error responses:
Common Error Codes:
  • VALIDATION_ERROR - Invalid request parameters
  • NOT_FOUND - Document not found
  • BAD_REQUEST - Invalid request format
  • FORBIDDEN - File format mismatch or access denied
  • INTERNAL_SERVER_ERROR - Storage service errors
Storage-Specific Errors:
  • Malformed ids: a documentId in the path that is not a 24-character hex id answers 400 with VALIDATION_ERROR, and a storage token whose orgId or userId is not one answers 400 with HTTP_BAD_REQUEST. The message names the id to fix. A well-formed id that matches no document is still 404.
  • Extension validation failures
  • File size limit exceeded
  • Storage vendor configuration errors
  • Version control constraint violations
  • MIME type validation failures
HTTP Status Codes:
  • 200 - Success
  • 308 - Permanent Redirect (for direct uploads)
  • 400 - Bad Request
  • 401 - Unauthorized
  • 403 - Forbidden
  • 404 - Not Found
  • 500 - Internal Server Error

Configuration Management

Storage configuration is maintained in etcd under /services/storage path:
Dynamic Configuration:
  • Service loads configuration at startup and via watch mechanism
  • Can switch storage vendors without service restart
  • Configuration changes trigger adapter reinitialization
  • Graceful handling of configuration errors

Important Notes

  1. Schema Discrepancy: There’s a mismatch between the rollback validator schema (expects version in query) and controller implementation (reads version from body). Documentation follows schema specification.
  2. File Extensions: Automatically detected from original filename and validated against comprehensive MIME type mappings.
  3. Version Control: Optional per document via isVersionedFile flag, maintains complete history with metadata and notes.
  4. Storage Abstraction: Seamless switching between storage vendors via configuration without code changes.
  5. Organization Isolation: All documents are organization-scoped (orgId) for secure multi-tenancy.
  6. Deletion: The delete endpoints mark a document as deleted (isDeleted: true). The exception is the internal delete with ?hard=true, which removes the document and makes one attempt to remove its stored files. Deleting a record, folder or knowledge base in PipesHub removes its stored files and their documents through the internal purge endpoints, asynchronously. The delete request finishes once the records are gone from the graph, and the indexing service removes the stored content afterwards:
    • An uploaded file’s removal is scheduled before its record is deleted. If it can’t be scheduled, nothing is deleted and the request returns 503.
    • While a record still lists the file, the indexing service re-schedules the removal, for up to a day after the delete. A file a record still lists after that belongs to a record that was never deleted, so it is kept.
    • If the record is gone but storage can’t remove the file, or the record can’t be checked, the removal is re-scheduled with a delay of up to 5 minutes until it succeeds, with no time limit.
    • A record’s processed content is removed by its delete event or, if that event is lost, by the indexing service’s periodic orphan sweep.
  7. Direct Upload: Large files bypass API server for optimal performance, using vendor-specific presigned URLs.
  8. Internal APIs: Service-to-service communication with scoped authentication using specific token scopes.
  9. Mutation Tracking: Documents track change count (mutationCount) for auditing and optimization.
  10. MIME Type Validation: Extensive validation against supported file types with automatic extension detection.
  11. Path Structure: Organized as {orgId}/PipesHub/{documentPath}/{documentId}/current|versions/ for clear file organization.
  12. Cross-Platform Support: Local storage handles Windows, macOS, and Linux filesystem differences transparently.