generated from nathanwoodburn/python-webserver-template
main
Upload Server
A lightweight, high-performance file upload service designed for both CLI (curl, shell alias) and web browser workflows.
Features
- CLI-First: Upload directly with
curlor using an installable shell alias (upload). - One-Command Setup: Install the shell function directly by serving it at
/bashrc:curl -sL https://your-server/bashrc >> ~/.bashrc && source ~/.bashrc - Custom Expiry: Specify expiration times (
30m,2h,1d,7d,30d,1y) or default to 7 days. Expired files are automatically cleaned up. - Delete URL: Every upload returns a dedicated delete URL (
/delete/<token>) allowing instantaneous one-shot deletion via CLI or confirmation in the browser. - Modify Link: Customize the link slug (vanity URL), update the expiration date, or replace the file content via
/modify/<token>or CLI. - List All Your Links: View active links uploaded from your machine or browser:
- CLI: Machine token persistence or header
X-User-Token/X-Machine-Idlists your CLI uploads (upload --listorcurl -H "X-User-Token: ..." .../list). - Browser: Cookie-based dashboard on the homepage and
/listwith instant token syncing between terminal and browser.
- CLI: Machine token persistence or header
Quick Start
1. Requirements
- Python 3.13+
- uv
2. Run the Development Server
uv sync
uv run python3 server.py
3. Run in Production (Gunicorn)
uv run python3 main.py
Usage Guide
A. Shell Alias (Recommended)
- Add the alias to your shell:
curl -sL http://localhost:5000/bashrc >> ~/.bashrc && source ~/.bashrc - Upload a file (default 7-day expiry):
upload photo.png - Upload with custom expiry and custom slug:
upload report.pdf 24h quarterly-report - Upload piped stdin:
cat /var/log/syslog | upload syslog.txt 1d - List active files uploaded by your machine:
upload --list - Modify link slug or expiry:
upload --modify <modify_token_or_url> new-slug 14d - Delete a file:
upload --delete <delete_token_or_url>
B. Upload with curl
Basic upload (default 7 days):
curl -F "file=@document.pdf" http://localhost:5000/
Upload with custom expiry:
curl -F "file=@document.pdf" -F "expires=3d" http://localhost:5000/
Upload with custom link slug:
curl -F "file=@document.pdf" -F "slug=my-docs" http://localhost:5000/
Get raw download URL only:
curl -s -F "file=@document.pdf" "http://localhost:5000/?raw=1"
Upload with JSON output:
curl -s -F "file=@document.pdf" -H "Accept: application/json" http://localhost:5000/
C. Link Management & Deletion
- Download:
http://localhost:5000/u/<slug>(or directhttp://localhost:5000/<slug>) - Delete:
curl -X POST http://localhost:5000/delete/<delete_token>(or open in browser for confirmation) - Modify:
curl -X POST http://localhost:5000/modify/<manage_token> -F "slug=new-slug" -F "expires=14d"
Testing & Quality
Run the test suite:
uv run pytest
Check linting and formatting:
uv run ruff check
uv run ruff format --check
Languages
Python
61.3%
HTML
37.5%
CSS
0.6%
Dockerfile
0.6%