Complete guide for programmatic access to the File Manager API. This API allows you to integrate file management into your applications, scripts, and automation workflows.
All API endpoints (except public file access) require authentication. The API supports two authentication methods:
Use this method for web-based interactions or when you need temporary access.
curl -c cookies.txt -X POST http://localhost:3000/api/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"admin123"}'
Response:
{
"success": true,
"message": "Login successful"
}
curl -b cookies.txt "http://localhost:3000/api/files"
Use this method for scripts, automation, CI/CD pipelines, or long-running processes.
Via Web Interface:
Via API:
curl -b cookies.txt -X POST http://localhost:3000/api/user/generate-token \
-H "Content-Type: application/json" \
-d '{"password":"your_password"}'
Response:
{
"success": true,
"message": "API token generated successfully",
"apiKey": "yknngagbkwqyga86qxeus5qd"
}
Option A: Bearer Token (Recommended)
curl -H "Authorization: Bearer YOUR_API_TOKEN" \
http://localhost:3000/api/files
Option B: URL Parameter
curl "http://localhost:3000/api/files?apiKey=YOUR_API_TOKEN"
Authenticate user and create session
Request Body:
{
"username": "admin",
"password": "your_password"
}
Response:
{
"success": true,
"message": "Login successful"
}
End current session
Response:
{
"success": true,
"message": "Logged out successfully"
}
Check authentication status
Response:
{
"authenticated": true,
"username": "admin"
}
List files and folders in a directory
Example:
# List root directory
curl -b cookies.txt "http://localhost:3000/api/files"
# List specific folder
curl -b cookies.txt "http://localhost:3000/api/files?path=products"
# With API token
curl -H "Authorization: Bearer YOUR_TOKEN" \
"http://localhost:3000/api/files?path=products"
Response:
{
"currentPath": "products",
"items": [
{
"name": "tshirt.jpg",
"path": "products/tshirt.jpg",
"isDirectory": false,
"size": 245678,
"modified": "2024-10-09T10:30:00.000Z",
"created": "2024-10-08T14:20:00.000Z"
}
]
}
Upload one or more files
Example - Single file:
curl -b cookies.txt -X POST http://localhost:3000/api/upload \
-F "basePath=products" \
-F "files=@/path/to/image.jpg"
Example - Multiple files:
curl -b cookies.txt -X POST http://localhost:3000/api/upload \
-F "basePath=products" \
-F "files=@image1.jpg" \
-F "files=@image2.jpg" \
-F "files=@image3.jpg"
With API token:
curl -H "Authorization: Bearer YOUR_TOKEN" \
-X POST http://localhost:3000/api/upload \
-F "basePath=products" \
-F "files=@image.jpg"
Create a new folder
Request Body:
{
"path": "products",
"name": "new-folder"
}
Example:
curl -b cookies.txt -X POST http://localhost:3000/api/folder \
-H "Content-Type: application/json" \
-d '{"path":"","name":"documents"}'
Delete a file or folder (recursive)
Request Body:
{
"path": "products/old-image.jpg"
}
Example:
curl -b cookies.txt -X DELETE http://localhost:3000/api/delete \
-H "Content-Type: application/json" \
-d '{"path":"products/old-image.jpg"}'
Rename a file or folder
Request Body:
{
"path": "products/old-name.jpg",
"newName": "new-name.jpg"
}
Download a file
Example:
curl -b cookies.txt "http://localhost:3000/api/download?path=products/image.jpg" \
-o downloaded-image.jpg
Get current user information
Response:
{
"success": true,
"user": {
"username": "john",
"role": "user",
"hasApiKey": true,
"apiKey": "yknngagbkwqyga86qxeus5qd",
"createdAt": "2025-01-15T10:00:00.000Z"
}
}
Change your password
Request Body:
{
"oldPassword": "current_password",
"newPassword": "new_password_min_8_chars"
}
Generate a new API token
Request Body:
{
"password": "your_password"
}
Response:
{
"success": true,
"message": "API token generated successfully",
"apiKey": "yknngagbkwqyga86qxeus5qd"
}
Delete your API token
Request Body:
{
"password": "your_password"
}
These endpoints require admin role.
List all users (admin only)
Response:
{
"success": true,
"users": [
{
"username": "admin",
"role": "admin",
"hasApiKey": true,
"createdAt": "2025-01-01T00:00:00.000Z"
},
{
"username": "john",
"role": "user",
"hasApiKey": false,
"createdAt": "2025-01-15T10:00:00.000Z"
}
]
}
Create a new user (admin only)
Request Body:
{
"username": "newuser",
"role": "user"
}
Response:
{
"success": true,
"message": "User created successfully",
"user": {
"username": "newuser",
"password": "randomly_generated_password_123",
"role": "user"
}
}
Delete a user (admin only)
Example:
curl -b cookies.txt -X DELETE http://localhost:3000/api/admin/users/olduser
# Or with API token
curl -H "Authorization: Bearer YOUR_ADMIN_TOKEN" \
-X DELETE http://localhost:3000/api/admin/users/olduser
Note: Admins cannot delete their own account.
Search for files and folders
Example:
curl -b cookies.txt "http://localhost:3000/api/search?q=tshirt"
Get storage statistics
Response:
{
"totalSize": 15728640,
"fileCount": 42,
"folderCount": 8
}
#!/bin/bash
# Step 1: Login
curl -c cookies.txt -X POST http://localhost:3000/api/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"admin123"}'
# Step 2: Create products folder
curl -b cookies.txt -X POST http://localhost:3000/api/folder \
-H "Content-Type: application/json" \
-d '{"path":"","name":"products"}'
# Step 3: Upload images
curl -b cookies.txt -X POST http://localhost:3000/api/upload \
-F "basePath=products" \
-F "files=@./tshirt-red.jpg" \
-F "files=@./tshirt-blue.jpg" \
-F "files=@./tshirt-green.jpg"
echo "Files are now accessible at:"
echo "http://localhost:3000/products/tshirt-red.jpg"
import requests
BASE_URL = "http://localhost:3000"
API_TOKEN = "yknngagbkwqyga86qxeus5qd"
# Set up headers with API token
headers = {
"Authorization": f"Bearer {API_TOKEN}"
}
# List files
response = requests.get(f"{BASE_URL}/api/files", headers=headers)
files = response.json()
print(f"Found {len(files['items'])} items:")
for item in files['items']:
icon = "š" if item['isDirectory'] else "š"
print(f" {icon} {item['name']}")
# Upload file
with open('example.txt', 'rb') as f:
files_data = {'files': f}
data = {'basePath': ''}
response = requests.post(
f"{BASE_URL}/api/upload",
files=files_data,
data=data,
headers=headers
)
print(f"\nā Upload: {response.json()['message']}")
const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
const BASE_URL = 'http://localhost:3000';
const API_TOKEN = 'yknngagbkwqyga86qxeus5qd';
const api = axios.create({
baseURL: BASE_URL,
headers: {
'Authorization': `Bearer ${API_TOKEN}`
}
});
async function main() {
try {
// List files
const files = await api.get('/api/files');
console.log(`Found ${files.data.items.length} items`);
// Create folder
await api.post('/api/folder', {
path: '',
name: 'test-folder',
});
console.log('ā Created folder: test-folder');
// Upload file
const formData = new FormData();
formData.append('basePath', 'test-folder');
formData.append('files', fs.createReadStream('./test.txt'));
await api.post('/api/upload', formData, {
headers: formData.getHeaders(),
});
console.log('ā Uploaded file');
} catch (error) {
console.error('Error:', error.response?.data || error.message);
}
}
main();
| Status Code | Error Type | Example Response |
|---|---|---|
| 401 | Unauthorized | {"error": "Authentication required"} |
| 403 | Forbidden | {"error": "Access denied"} |
| 404 | Not Found | {"error": "File or folder not found"} |
| 400 | Bad Request | {"error": "Invalid input"} |
| 500 | Server Error | {"error": "Internal server error"} |
If you encounter any issues or have questions, please refer to the troubleshooting section in the main documentation or contact support.
Made with ā¤ļø for easy file management
Powered by Simple File Manager | Licensed under MIT License
ā Back to File Manager