Spaces:
Sleeping
Sleeping
metadata
title: MinIO Storage API
emoji: ποΈ
colorFrom: blue
colorTo: green
sdk: docker
app_file: app.py
pinned: false
license: mit
MinIO File Storage Service
A complete file storage API with FastAPI backend, MinIO object storage, and PostgreSQL metadata management.
π Features
- π Dual Authentication - JWT tokens and API keys
- π― Granular Permissions - Fine-grained access control
- π Public File Sharing - Share files with public URLs
- π Project-based Storage - Isolated storage per project
- π API Key Management - Generate keys with specific permissions
- π€ Direct Upload API - Upload files with API keys
- πΌοΈ Inline File Viewing - View images, PDFs in browser
- β¬οΈ Public Downloads - Download files without authentication
π API Key Permissions
| Permission | Description |
|---|---|
read |
View file metadata |
write |
Upload new files |
delete |
Delete files |
list |
List all files |
public |
Generate public URLs |
download |
Download files |
Permission Presets
- Read-only:
read,list,download - Upload only:
write - Full access:
read,write,delete,list,public,download
π Quick Start
1. Initialize Admin
POST /init-admin
2. Login
POST /auth/login
{
"username": "admin",
"password": "your_admin_password"
}
3. Create Project
POST /projects
Authorization: Bearer <your_jwt_token>
{
"name": "My Project",
"description": "Project description"
}
4. Generate API Key
POST /projects/{project_id}/api-keys
Authorization: Bearer <your_jwt_token>
{
"name": "Upload Key",
"permissions": "write,public",
"description": "Key for uploading files"
}
5. Upload Files
curl -X POST "https://godfreyowino-minio-storage-api.hf.space/api/upload" \
-H "X-API-Key: sk_your_api_key" \
-F "file=@image.jpg"
π API Endpoints
Authentication
POST /auth/register- Register userPOST /auth/login- Login userGET /users/me- Get user infoPOST /init-admin- Initialize admin
Projects (JWT Required)
POST /projects- Create projectGET /projects- List projectsGET /projects/{id}- Get project
API Keys (JWT Required)
POST /projects/{id}/api-keys- Create API keyGET /projects/{id}/api-keys- List API keysDELETE /projects/{id}/api-keys/{key_id}- Revoke key
Files (JWT Auth)
POST /projects/{id}/upload- Upload fileGET /projects/{id}/files- List filesGET /projects/{id}/files/{file_id}/download- DownloadDELETE /projects/{id}/files/{file_id}- Delete
Files (API Key Auth)
POST /api/upload- Upload fileGET /api/files- List filesGET /api/files/{file_id}- Get file metadataGET /api/files/{file_id}/download- DownloadGET /api/files/{file_id}/public-url- Get public URLDELETE /api/files/{file_id}- Delete
Public Access (No Auth)
GET /public/files/{file_id}- View file inlineGET /public/download/{file_id}- Download file
π» Usage Examples
Python
import requests
API_KEY = "sk_your_api_key"
BASE_URL = "https://godfreyowino-minio-storage-api.hf.space"
# Upload file
with open("image.jpg", "rb") as f:
response = requests.post(
f"{BASE_URL}/api/upload",
headers={"X-API-Key": API_KEY},
files={"file": f}
)
result = response.json()
print(f"Public URL: {result['public_url']}")
# List files
response = requests.get(
f"{BASE_URL}/api/files",
headers={"X-API-Key": API_KEY}
)
files = response.json()
JavaScript
const API_KEY = "sk_your_api_key";
const BASE_URL = "https://godfreyowino-minio-storage-api.hf.space";
// Upload file
const uploadFile = async (file) => {
const formData = new FormData();
formData.append('file', file);
const response = await fetch(`${BASE_URL}/api/upload`, {
method: 'POST',
headers: { 'X-API-Key': API_KEY },
body: formData
});
const data = await response.json();
return data.public_url;
};
HTML
<!-- Display image -->
<img src="https://godfreyowino-minio-storage-api.hf.space/public/files/{file-id}"
alt="Uploaded image">
<!-- Download link -->
<a href="https://godfreyowino-minio-storage-api.hf.space/public/download/{file-id}">
Download File
</a>
π§ Environment Variables
Required variables for HuggingFace Spaces:
DATABASE_URL=your_postgresql_url
MINIO_ENDPOINT=localhost:9000
MINIO_ACCESS_KEY=minioadmin
MINIO_SECRET_KEY=minioadmin
MINIO_SECURE=false
SECRET_KEY=your_secret_key
ADMIN_USERNAME=admin
ADMIN_PASSWORD=your_admin_password
PUBLIC_URL=https://godfreyowino-minio-storage-api.hf.space
π Documentation
Interactive API docs: /docs
License
MIT License