Building a Self-Hosted LAN File Transfer Web App
Build notes from PocketBridge, an open-source LAN file transfer web UI that streams large uploads to disk, shows progress and ETA, and protects access with a PIN.
Moving a 15 GB video from a phone to a laptop should not involve uploading it to the cloud and downloading it again. A LAN file transfer tool keeps the bytes on your own network, where they move as fast as your router allows.
I built PocketBridge, an open-source, self-hosted web UI for exactly this. Run it on any machine, open the address from a phone browser, and send files up to 20 GB. This post covers the design decisions that make that work reliably: streaming to disk, honest progress and ETA, and enough security for a shared network.
TL;DR
Serve a small web app on a machine in your local network, accept uploads as streams written directly to disk, report progress from the browser's upload events, protect access with a PIN, and keep the process alive with PM2. No app install is needed on the sending device, and memory use stays flat even for very large files.
key takeaways
- A browser-based LAN file transfer tool needs no app installs, so any phone, tablet or laptop on the same network can use it.
- Large uploads must be streamed straight to disk, because buffering a multi-gigabyte file in memory will crash the server.
- Progress and ETA come from the browser's upload events, and they matter more to users than raw speed.
- Even on a home or office network, a simple PIN and binding to the local interface prevent casual access.
Why a web UI beats the alternatives
There are plenty of ways to move files locally. Each has a catch.
| Method | Install needed | Large files | Cross-platform | Catch |
|---|---|---|---|---|
| Cloud drive | App or browser | Size limits, slow | Yes | Goes through the internet twice |
| Bluetooth / nearby share | Built in | Very slow | Partly | Vendor ecosystems do not talk to each other |
| SMB / network share | OS config | Good | Mostly | Setup friction on phones |
| USB cable | Cable, drivers | Good | Mostly | Phone file access is often clumsy |
| Local web app | Nothing on sender | Good if streamed | Any browser | Needs one machine running the server |
A browser is the one client every device already has. That is the whole pitch: one server, zero installs everywhere else.
Streaming uploads to disk, not RAM
This is the core engineering problem. Many upload tutorials parse the whole request into memory, then save it. That works for a 2 MB photo and fails badly at 20 GB.
The approach
- The browser sends the file as the raw request body (or a multipart stream), with the file name and size in headers or the form.
- The server opens a write stream to a temporary file in the target directory.
- Incoming chunks are piped to the write stream. Node's
pipeline()handles backpressure, so if the disk is slower than the network, reading pauses instead of buffering. - When the stream finishes and the byte count matches the declared size, the temp file is renamed to its final name.
- If the client disconnects or sizes do not match, the temp file is deleted.
In a Next.js route handler, the request body is a web ReadableStream. Convert it with Readable.fromWeb() and pipe it into fs.createWriteStream(). The Next.js route handler docs describe the request object you get.
Details that matter at 20 GB
- Disable body parsing and size limits for the upload route only, so the framework does not try to buffer or reject the body.
- Check free disk space before accepting, using the declared size. Failing at 19 GB is far worse than failing at 0.
- Sanitize file names. Strip path separators and
..so a name cannot escape the upload directory. Handle duplicates by appending a counter. - Raise proxy timeouts if Nginx sits in front, and turn off request buffering for the route, or the proxy will spool the whole file first.
- Write temp files on the same filesystem as the destination so the final rename is instant.
Progress, ETA and the user experience
Users judge a transfer tool by whether they trust it. A frozen screen during a 10-minute upload feels broken even when it is working.
On the client, XMLHttpRequest.upload.onprogress reports bytes sent. From that:
- Percentage is
loaded / total. - Speed should be a moving average over the last few seconds, not the overall average, so it reacts when Wi-Fi changes.
- ETA is remaining bytes divided by the smoothed speed. Round it to friendly units and avoid updating the text more than once a second.
Other touches that help:
- Queue multiple files and show per-file and total progress.
- Keep the screen awake during transfers on mobile where the browser allows it.
- Show the server's LAN address and a QR code on the host machine, so phones can connect without typing an IP.
- Provide a clear success state with the saved file name and size.
Security on a local network
"It is only my Wi-Fi" is not a security model, especially on office or shared networks.
- PIN protection. Require a PIN before uploads or downloads, and set a session cookie after it is entered. Rate-limit wrong attempts.
- Bind to the LAN. Listen on the local interface, and never port-forward the app to the internet.
- Restrict the directory. Only read and write inside one configured folder.
- No directory traversal. Validate every path parameter on downloads as strictly as uploads.
- Log transfers with time, client IP, file name and size.
If you ever need remote access, put it behind a VPN rather than exposing the app directly.
How I built this in practice
PocketBridge is open source and self-hosted. It is a Next.js app that runs under PM2, so it restarts if it crashes and comes back after a reboot. Uploads stream to disk rather than RAM, which is what makes files up to 20 GB practical on modest hardware. The UI shows progress and ETA, and a PIN gates access.
The same streaming discipline shows up in client work. In the audit portal I built for an Australian accounting firm, documents go to Azure Blob Storage and are served through time-limited signed URLs rather than through the app server. In Client Mitra, files go to Cloudinary. The rule is consistent: never hold a whole file in application memory if you can stream it or hand it off.
Common mistakes
- Parsing uploads into memory with a default body parser and crashing on the first large file.
- Leaving framework or proxy body size limits in place, causing silent failures near the end.
- Trusting the client-provided file name and allowing path traversal.
- Calculating ETA from the overall average speed, which makes it wildly wrong after a Wi-Fi dip.
- Not cleaning up partial temp files after cancelled uploads, slowly filling the disk.
- Port-forwarding a LAN tool to the internet for convenience.
keep reading
FAQ
What is the fastest way to transfer files over a LAN?+
For occasional transfers, a local web app or SMB share over Wi-Fi or Ethernet is fast and avoids cloud upload limits. Wired Ethernet is usually much faster and more consistent than Wi-Fi for multi-gigabyte files.
Why not just use a cloud drive?+
Cloud drives upload over your internet connection and then download again, which is slow for large files and may have size limits. A LAN transfer stays on the local network, so speed is limited only by your router and devices.
How do you upload a 20 GB file through a browser without crashing the server?+
Stream the request body directly to a file on disk instead of parsing it into memory. Node's streams with backpressure write chunks as they arrive, so memory use stays flat regardless of file size.
Is a self-hosted file transfer app safe on my network?+
It can be if you keep it on the local network, avoid port forwarding, add a PIN or password, and sanitize file names. Do not expose it to the internet without proper authentication and TLS.
Devang Gandhi
AI & full stack developer at Passdn, building CRMs, SaaS, AI agents and Flutter apps for clients in the US, UK, Australia, UAE and India. More about me