Upload files and get short links.
- Step up an S3 bucket in us-west-1 (maybe this should be configurable). Optionally, set up a CloudFront distribution for that bucket.
-
make build
will give you anapp
executable you can deploy where ever (I use fly.io).make run
will compile and run the app, which is useful for development.
- Run it with some environment variables (or pass as flags):
PORT
: What port to listen onKEY
: An AWS keySECRET
: An AWS secretBUCKET
: The S3 bucket to store content inCDN
(Optional): A CDN URL to use with your S3 object keys. If blank, will use pre-signed S3 URLs instead.USERNAME
(Optional): A username to secure uploading behind with basic authenticationPASSWORD
(Optional): A password to secure uploading behind with basic authenticationPLAUSIBLE
(Optional): A domain to use with Plausible for metrics
I wanted to avoid having a databass and minimal additional libraries, so S3 keys are tied directly to file content, rather than any ID creation. Files are SHA-256 hashed which is then URL safe base 64 encoded without padding and used as a prefix for the key. The original file name is then appended to that, as to retain the original name when downloaded or displayed.
Lookup URLs are then shortened versions of that base 64 encoded hash, and S3 keys are looked up by that prefix. The length of that prefix can be increased if you're concerned about hash collisions.