Skip to content

icefields/self-hosted-sharelink

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Simple Share - Upload Tool

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.

πŸ”§ Setup Instructions

  1. Clone the repository
  2. Create and activate a Python virtual environment
  3. Install dependencies
pip install flask python-dotenv

βš™οΈ Configuration

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

πŸš€ Run the Server

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.

πŸ” Uploading a File (with Auth Token)

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"}

πŸ“‚ Serving Uploaded Files

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.

Auto Cleanup

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.

πŸ›‘οΈ Security Notes

  • 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).

βœ… To-Do

  • Add file size/type restrictions
  • Add logging or rate limiting
  • Dockerize the application
  • Systemd service integration for persistence

About

a solution to self host your shared links and files, without bloat

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages