Files
simplefileupload-server/README.md

152 lines
3.5 KiB
Markdown
Raw Normal View History

2025-04-14 20:47:26 -04:00
# Simple File Upload Server
2024-10-07 23:19:53 -04:00
2025-04-14 20:47:26 -04:00
A lightweight Flask-based file upload and download server with a modern UI. Perfect for temporary file sharing and mobile app log uploads.
## Features
- Clean, modern UI for file downloads
2025-04-15 07:44:20 -04:00
- Secure API authentication for uploads
2025-04-14 20:47:26 -04:00
- Mobile-friendly upload endpoint
- Secure 6-digit alphanumeric code system
- Automatic file cleanup
- Configurable download limits and expiry times
- User-friendly error pages
- Docker support
## Architecture
Built using the MVC design pattern:
- **Model**: File metadata management (code, path, downloads, expiry)
- **View**: Modern HTML templates with client-side validation
- **Controller**: Upload/download logic with error handling
## Getting Started
### Local Development
2025-04-15 07:44:20 -04:00
1. Clone the repository
2. Create and activate a virtual environment:
2025-04-14 20:47:26 -04:00
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
2025-04-15 07:44:20 -04:00
```
2025-04-14 20:47:26 -04:00
2025-04-15 07:44:20 -04:00
3. Install dependencies:
```bash
2025-04-14 20:47:26 -04:00
pip install -r requirements.txt
2025-04-15 07:44:20 -04:00
```
2025-04-14 20:47:26 -04:00
2025-04-15 07:44:20 -04:00
4. Set up environment variables:
- Copy `.env.example` to `.env`
- Set your `CLIENT_KEY` in the `.env` file
- Adjust other settings as needed
5. Run the server:
```bash
2025-04-14 20:47:26 -04:00
python src/app.py
```
### Docker Deployment
2025-04-15 07:44:20 -04:00
1. Build the image:
2025-04-14 20:47:26 -04:00
```bash
docker build -t file-upload-server .
2025-04-15 07:44:20 -04:00
```
2025-04-14 20:47:26 -04:00
2025-04-15 07:44:20 -04:00
2. Run the container:
```bash
docker run -p 7777:7777 \
-e CLIENT_KEY=your-secret-key \
-v $(pwd)/tmp:/app/tmp \
file-upload-server
2025-04-14 20:47:26 -04:00
```
## API Endpoints
### POST /upload
Upload a file and receive a download code.
2025-04-15 07:44:20 -04:00
**Authentication:**
- Required: `X-Client-Key` header with your API key
2025-04-14 20:47:26 -04:00
**Form Fields:**
- `file`: File to upload (required)
- `max_downloads`: Maximum download count (optional, default: 1)
2025-04-15 07:44:20 -04:00
- `expiry_hours`: Hours until expiry (optional, default: 24)
2025-04-14 20:47:26 -04:00
**Response:**
```json
{
"code": "ABC123"
}
```
2025-04-15 07:44:20 -04:00
**Error Responses:**
- 401: Invalid or missing client key
- 400: Missing file or invalid request
```json
{
"error": "Error message here"
}
```
2025-04-14 20:47:26 -04:00
### GET /download/{code}
Download a file using a 6-character code.
**Responses:**
- 200: File download starts
2025-04-15 07:44:20 -04:00
- 404: File not found with specific error pages for:
2025-04-14 20:47:26 -04:00
- Invalid code
- Expired file
- Download limit reached
- File no longer exists
2025-04-15 07:44:20 -04:00
### DELETE /delete/{code}
Delete a file using its code.
**Responses:**
- 200: File deleted successfully
- 404: File not found or expired
## Security Features
- **API Authentication**: Client key required for file uploads
- **Secure Downloads**: 6-digit alphanumeric codes
- **Auto Cleanup**: Files are automatically deleted after:
2025-04-14 20:47:26 -04:00
- Reaching download limit
- Exceeding expiry time
- Server restart (temporary storage)
2025-04-15 07:44:20 -04:00
- **Upload Security**:
- Secure filename handling
- No file execution permissions
- File size limits
2025-04-14 20:47:26 -04:00
## Configuration
All configuration is handled through environment variables:
2025-04-15 07:44:20 -04:00
### Required Settings
- `CLIENT_KEY`: API key for file uploads (required for production)
### Optional Settings
2025-04-14 20:47:26 -04:00
- `UPLOAD_FOLDER`: Upload directory path (default: tmp/uploads)
- `MAX_CONTENT_LENGTH`: Maximum file size (default: 16MB)
- `DEBUG`: Enable debug mode (default: False)
2025-04-15 07:44:20 -04:00
### Environment File
The application supports `.env` file for configuration:
```env
CLIENT_KEY=your-secret-key-here
UPLOAD_FOLDER=tmp/uploads
DEBUG=False
MAX_CONTENT_LENGTH=16777216
```
2025-04-14 20:47:26 -04:00
## Contributing
1. Fork the repository
2. Create a feature branch
3. Commit your changes
4. Push to the branch
5. Create a Pull Request
2025-04-15 07:44:20 -04:00
## Security Best Practices
- Always change the default client key
- Use HTTPS in production
- Regularly monitor disk usage
- Set appropriate file size limits
- Keep dependencies updated