Skip to main content

upload-file

Upload File

Sprint 3

Upload a file to MinIO/S3 storage with quota checking. Files are automatically assigned unique filenames to prevent overwrites.

Account Type & Use Case

Endpoint

POST /api/v1/storage/upload

Headers

HeaderRequiredDescription
AuthorizationYesBearer <access_token>
Content-TypeYesmultipart/form-data

Form Data

FieldTypeRequiredDescription
filefileYesFile to upload
pathstringNoOptional path prefix for the file (e.g., "data-sources/org-123/")
file_categorystringNoFile category: data_source, profile_image, general (default: data_source)

Response

Success (201)

{
"success": true,
"data": {
"file_path": "organizations/1/files/123/report_20241203_101500_abc123.csv",
"file_name": "report.csv",
"unique_file_name": "report_20241203_101500_abc123.csv",
"size": 1024000,
"content_type": "text/csv",
"s3_uri": "s3://rivergen-storage/organizations/1/files/123/report_20241203_101500_abc123.csv",
"storage_file_id": 1
},
"message": "File uploaded successfully"
}

Error Codes

StatusCodeDescription
401UNAUTHORIZEDInvalid or missing authentication token
413REQUEST_ENTITY_TOO_LARGEStorage quota exceeded
500INTERNAL_SERVER_ERRORFailed to upload file

Features

  • Automatic unique filename generation (timestamp + UUID)
  • Quota checking before upload
  • Organization-based file structure
  • File metadata tracking
  • Returns storage_file_id for use in data source creation
  • Original filename preserved for display

Unique Filename Format

Files are automatically renamed to prevent overwrites:

  • Format: {original_name}_{YYYYMMDD_HHMMSS}_{uuid8}.{ext}
  • Example: report_20241203_101500_abc123.csv

File Organization

Files are stored in the following structure:

organizations/{organization_id}/files/{user_id}/{unique_filename}

Quota Checking

  • Quota is checked before file upload
  • Upload is rejected if quota would be exceeded
  • Quota is updated automatically after successful upload

Example

curl -X POST "https://api.rivergen.com/api/v1/storage/upload" \
-H "Authorization: Bearer <access_token>" \
-F "file=@report.csv" \
-F "file_category=data_source"