Files
2026-03-08 21:11:43 +05:30

95 lines
2.3 KiB
Markdown

# filehost
A minimal self-hosted file sharing tool. Upload a file, get a public link. Files are stored on Cloudflare R2 and expire after 24 hours.
**Stack:** Next.js 15 (frontend) · FastAPI (backend) · Cloudflare R2 (storage)
---
## How it works
1. Enter the upload password to authenticate
2. Drop a file or click to browse (250 MB max)
3. Copy the public link and share it
The frontend proxies `/api/*` to the backend at `localhost:8000`, so both run separately during development.
---
## Prerequisites
- [Node.js](https://nodejs.org/) 18+
- [Python](https://www.python.org/) 3.11+
- [uv](https://docs.astral.sh/uv/) (Python package manager)
- A [Cloudflare R2](https://developers.cloudflare.com/r2/) bucket with public access enabled
> **Upload limit:** 250 MB per file. Files are streamed directly through the backend to R2 without being loaded into memory.
---
## Environment setup
Create `backend/.env`:
```
R2_ENDPOINT=https://<account-id>.r2.cloudflarestorage.com
R2_ACCESS_KEY=<your-r2-access-key-id>
R2_SECRET_KEY=<your-r2-secret-access-key>
R2_BUCKET=<your-bucket-name>
PUBLIC_URL=https://<your-public-bucket-url>
UPLOAD_PASSWORD=<choose-a-password>
```
> `PUBLIC_URL` is the public base URL of your R2 bucket (e.g. `https://pub-xxx.r2.dev` or a custom domain). It must include `https://`.
---
## Running locally
### Backend
```sh
cd backend
uv venv
source .venv/bin/activate
uv pip install -r requirements.txt
uvicorn app.main:app --reload
```
Runs on `http://localhost:8000`.
### Frontend
```sh
cd frontend
npm install
npm run dev
```
Runs on `http://localhost:3000`.
Open `http://localhost:3000` in your browser.
---
## Project structure
```
filehost/
├── backend/
│ ├── app/
│ │ ├── config/
│ │ │ └── settings.py # Pydantic settings (reads .env)
│ │ ├── services/
│ │ │ └── r2.py # Cloudflare R2 upload logic
│ │ └── main.py # FastAPI app, /auth and /upload routes
│ ├── requirements.txt
│ └── .env # ← you create this
└── frontend/
├── src/app/
│ ├── page.tsx # Upload UI
│ ├── layout.tsx
│ └── globals.css
└── next.config.ts # Proxies /api/* → localhost:8000
```