Upload and manage files with the SimplyStack Storage API featuring automatic CDN distribution.
Storage API
The Storage API provides file upload and management capabilities with automatic CDN distribution. Perfect for user uploads, media libraries, and serving static assets.
Authentication
Storage API requires a project-specific API key. Get your key from Settings → API Keys in your project dashboard.
Upload File
POST /api/v1/storage
Upload a file to your project storage. Files are automatically distributed via CDN for fast delivery worldwide.
const formData = new FormData();
formData.append('file', fileInput.files[0]);
const response = await fetch('https://www.simplystack.dev/api/v1/storage', {
method: 'POST',
headers: {
'x-api-key': 'your-project-api-key'
},
body: formData
});
const { data } = await response.json();
console.log('File URL:', data.url);Response includes the file URL, metadata, and CDN information:
{
"data": {
"id": "file-uuid",
"url": "https://cdn.simplystack.dev/files/your-file.jpg",
"filename": "your-file.jpg",
"size": 1024000,
"mimetype": "image/jpeg",
"created_at": "2024-01-15T10:30:00Z"
}
}List Files
GET /api/v1/storage
Retrieve all files in your project with pagination.
const response = await fetch(
'https://www.simplystack.dev/api/v1/storage?page=1&limit=20',
{ headers: { 'x-api-key': 'your-project-api-key' } }
);
const { data, pagination } = await response.json();Get File Metadata
GET /api/v1/storage/{id}
Get metadata for a specific file by ID.
const response = await fetch(
`https://www.simplystack.dev/api/v1/storage/${fileId}`,
{ headers: { 'x-api-key': 'your-project-api-key' } }
);Delete File
DELETE /api/v1/storage/{id}
Delete a file from storage. This removes it from the CDN as well.
const response = await fetch(
`https://www.simplystack.dev/api/v1/storage/${fileId}`,
{
method: 'DELETE',
headers: { 'x-api-key': 'your-project-api-key' }
}
);Best Practices
- Validate file types before upload
- Set appropriate size limits for your use case
- Use unique filenames to avoid conflicts
- Implement error handling for failed uploads
- Clean up unused files periodically