This is a small Python/Flask-based file upload server. It stores uploaded files in a local folder and returns a public URL. A simple token-based authentication mechanism is included.
- Clone the repository
- Create and activate a Python virtual environment
- Install dependencies
pip install flask python-dotenv
Create a .env
file in the same directory as app.py
with the following content:
UPLOAD_TOKEN=abcde1234
PUBLIC_URL_BASE=https://yourdomain.net:port
UPLOAD_FOLDER=/home/youruser/shared-uploads
PUBLIC_URL_BASE is the url exposed to the public and will be returned by the script after upload (PUBLIC_URL_BASE}/{filename}
).
UPLOAD_TOKEN is an arbitrary string to be used for authentication.
UPLOAD_FOLDER is the location on your server where the files will live. This directory will be served by the file server. Make sure the upload folder exists and is writable by the user running the app:
mkdir -p /home/youruser/shared-uploads
chmod 755 /home/youruser/shared-uploads
Activate your virtual environment:
source venv/bin/activate
Then run the app:
python app.py
The server will listen on http://0.0.0.0:5011
.
Use the following curl
command to upload a file:
curl -k -X POST \
-H "X-Auth-Token: abcde1234" \
-F "file=@/path/to/your/file.mp4" \
https://yourdomain.net:5011/upload
If the token is valid, youβll receive a response like:
{"public_url": "https://yourdomain.net:port/uuid-filename.mp4"}
This server does not serve the uploaded files directly on port 6011. You must run a separate file server (like Python's built-in HTTP server, Apache, nginx, or Caddy) to expose the folder defined in UPLOAD_FOLDER
.
Example using Pythonβs built-in HTTP server:
cd /home/youruser/shared-uploads
python3 -m http.server 6011
Make sure this port is accessible and served over HTTPS, if needed.
You might want to periodically cleanup the upload directory.
sudo vim /etc/tmpfiles.d/upload-cleanup.conf
add this line (replace the amount of days to keep the files, path, user and group)
D /home/youruser/shared-uploads 0755 youruser youruser 7d
To apply it immediately:
sudo systemd-tmpfiles --clean
systemd will take care of running this, without further configuration.
-
Authentication uses a static token passed via the
X-Auth-Token
header. -
Do not expose this service directly to the internet without:
- HTTPS
- Firewall rules
- Possibly IP whitelisting or rate limiting
-
For production, consider stronger authentication mechanisms (e.g. API keys, OAuth, or JWT).
- Add file size/type restrictions
- Add logging or rate limiting
- Dockerize the application
- Systemd service integration for persistence