Upload files and get short links.
- Set up an S3 bucket (defaults to us-west-1, configurable via
REGION). Optionally, set up a CloudFront distribution for that bucket. -
make buildwill give you anappexecutable you can deploy where ever (I use fly.io).make runwill 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 inREGION(Optional): The AWS S3 region (defaults tous-west-1)CDN(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.
