Skip to main content

overview

Storage API

Sprint 32024-12-XX
Quick Navigation

The Storage API handles file storage operations for MinIO/S3, including file uploads, downloads, metadata management, and quota tracking.

Account Type & Use Case

Overview

This module provides:

  • File upload and download
  • Bucket and object management
  • Presigned URL generation
  • Storage quota management
  • File metadata tracking
  • User-scoped file access
  • File categorization (data_source, profile_image, general)

Storage Flow

The Storage API handles the complete file upload and management workflow, from quota validation through secure storage and metadata tracking. The flow ensures files are properly validated, encrypted, stored securely, and tracked for quota management and access control.

Storage Flow Diagram

View Flow Diagram

Storage Flow Diagram

Storage Flow Overview:

This flow diagram illustrates the file upload and management workflow. It demonstrates how files are validated, encrypted, uploaded to storage, and tracked for quota management and access control.

Key Flow Components:

  1. Quota Validation: System checks organization storage quota before accepting file uploads
  2. File Validation: Validates file type, size, and format to ensure compatibility
  3. Unique Filename Generation: Automatically generates unique filenames using timestamps and UUIDs to prevent overwrites
  4. File Encryption: Encrypts file data before storage for security
  5. S3/MinIO Upload: Uploads encrypted files to object storage with proper organization and user scoping
  6. Metadata Storage: Stores file metadata including size, content type, upload timestamp, and file path
  7. Quota Tracking: Updates organization quota usage after successful uploads
  8. Use Case Routing: Files can be used for data sources, profile images, or general storage

Internal Developer Notes:

  • Quota checking prevents exceeding organization limits before upload begins
  • Unique filenames use format: {original_name}_{YYYYMMDD_HHMMSS}_{uuid8}.{ext}
  • Files are stored in hierarchical structure: organizations/{org_id}/files/{user_id}/{filename}
  • User-scoped access ensures users can only access their own files
  • File deletion automatically updates quota usage
  • Presigned URLs are generated for secure file access with configurable expiration

Base Path

All storage endpoints are prefixed with /api/v1/storage

Authentication

All endpoints require authentication:

Authorization: Bearer <access_token>

File Organization

Files are organized in the following structure:

organizations/{organization_id}/files/{user_id}/{unique_filename}
  • Each user has their own folder within their organization
  • Files are automatically assigned unique filenames (timestamp + UUID)
  • Original filenames are preserved for display

Storage Quota

  • Quota checking before file upload
  • Organization-based quota limits
  • Automatic quota tracking
  • Quota recalculation option
  • Quota limits based on organization plan

Security

  • Users can only access files under their own folder: organizations/{org_id}/files/{user_id}/
  • Path validation prevents directory traversal
  • Presigned URLs with configurable expiration
  • Organization-scoped access control

Endpoints

MethodEndpointDescription
GET/bucketsList all available buckets
GET/buckets/{bucket_name}/objectsList objects in a bucket (user's files only)
GET/filesList user's uploaded files with pagination
POST/uploadUpload a file with quota checking
GET/objects/{object_name}/metadataGet file metadata
GET/objects/{object_name}/presigned-urlGet presigned URL for file access
DELETE/objects/{object_name}Delete a file
GET/usageGet storage usage and quota
GET/quotaGet storage quota limits

Internal Notes

  • All endpoints are fully implemented
  • Files are stored in MinIO/S3-compatible storage
  • Unique filenames prevent overwrites (timestamp + UUID)
  • Quota checking prevents exceeding limits
  • File deletion updates quota automatically
  • User-scoped access (users can only access their own files)
  • File categories: data_source, profile_image, general

Swagger Documentation

Interactive API documentation available at: /docs#/storage