Logo

File Sharing

A web service to share files

Ezekiel Lopez

Ezekiel Lopez

9/10/2024 · 3 min read

A screenshot of my file-sharing app

LET’S SHARE SOME FILES

Today I’m including some of my actual handwritten code to demo the project! You are welcome to use this in your own deployments 💞

live site
code

The problem:

Often, I find myself wanting to share a file. Maybe it’s my resume, or something a bit more sensitive. I don’t want just anyone to open it, and I don’t want to leave it sitting online forever. Finding a way to share can involve using google drive, or some other file hosting solution. But what if I want the file to automatically be deleted a few minutes after someone downloads it?

The solution:

Create my own file sharing solution with automatic file removal.

Overview:

I love pocketbase, and it can handle storing files, and drawing a relationship with a key and that file. I can use a simple little frontend which allows someone to type in a key, and provides them a link to download a file. Ezpz lemon squeezy.

The stack one more time:

  • Express.js on Node.js
  • PocketBase
  • React
  • react-router-dom
  • DaisyUI
  • Docker
  • CapRover

Details:

First thing first, a simple UI in react. All I need is some centered form, with a text input and a button.

Now let’s throw on some router magic, so that I can share a link i.e. domain.tld/key and “key” is automatically placed into the input field! Now people don’t have to type :D No need to worry about a “key” being insecure in the address, it will self destruct once the end person opens it!

Okay well how will it self destruct? Express can serve our react app, and we can add an /api route for handling retrieving the file from pocketbase. This way, we can hide our pocketbase secrets for convinence, and we can create a timeout for each request. Once the timeout triggers, it will simple remove the file from pocketbase and viola no more file.

Improvements:

Right now I upload my files to share just through the pocketbase UI. It’s good enough for me, but maybe it would make sense to offer uploading files from some sort of admin ui. Maybe you could make an account and have your own files to share. Honestly google drive should just add self destructing files. There’s probably other services like this, but I wanted to whip my own up quickly so I could trust the process and own the infestructure.

Thoughts?

Making this, I took extra effort to put my secrets in .env files so I could create a github and upload the code there for sharing. I was talking to someone the other day, and they asked if they could see actual code I wrote. I looked through the content I have that’s not under some NDA and all my quick personal projects seem to have secrets hardcoded in. Hard to feel safe sharing those projects source, so I kept that in mind making this. It’s also been super useful at the most surprising of times. I often just find myself needing to share a file and this does just that.

Thanks for reading 😁

live site
code