Serverless Userpics
update:someone spammed the repo. lol github is a mess.
Usage (Important)
To get started quickly,
- Head over to userpics.devclad.com and “Get a random user pic”.
- Use the URL in your app.
Alternatively (I recommend this),
- make a
GET
request tohttps://userpics.devclad.com/api/random
. - make a
GET
request to the URL in the response. - Stream the bytes to a new file in the desired format and save it to the bucket of your choice. (wherever you are storing your user pics)
- example: I use Django with S3 storage and they go in
media/avatars/
. I use theuuid
of the user as the filename.
- example: I use Django with S3 storage and they go in
Instantly get user avatars via an API call. Configurable af. I was using avatars.dicebear.com for a while, but I found some better avatars and decided to host my own serverless version of it.
Will be using this in production on DevClad. Live at userpics.devclad.com
Features
- Generate avatars on the fly
- Tiny as fuck even with stupid inline comments (~ 100 lines of code)
- Serverless on the EDGEEEEEEEEE. zooom bitch
- Configurable as fuck
Config
accountId := os.Getenv("ACCOUNT_ID")
bucketName := os.Getenv("BUCKET_NAME")
accessKeyId := os.Getenv("API_ACCESS_KEY")
accessKeySecret := os.Getenv("API_SECRET_KEY")
Replicate this
- Create an R2 bucket on Cloudflare.
- Generate S3 Token via
Manage R2 API Tokens
in R2 Dashboard. - Set your environment variables.
- Deploy ⚡
Running locally
do the usual. install dependencies via yarn
and run yarn run start
/yarn run dev
.
Make sure to setup environment variables in your Vercel dashboard. Also make sure to have S3 API access and secret on the recieving end if your bucket is private like mine.
Services
Resource | Service |
---|---|
Storage | Cloudflare R2 (S3 compatible) |
Serverless Hosting | Vercel (AWS Lambda) |
Avatars? | Craftwork.design |
Todo
- Add more avatars
- Host
- Modify
/
route. - Make the function URL public (?)
YANKING
Yanked the public/ and the vercel.json from template-go-vercel.