Thinking of more full-stack Cloudflare teething issues. Turns out its really hard to connect to d1 remotely? but how does drizzle do this with their d1 client I wonder? .
https://zzai.tech/blog/connect-d1-database-remotely-from-local-svelte-development
displaying r2 image objects as urls the hard way:
const APP_BUCKET = Astro.locals.runtime.env.APP_BUCKET;
const image = await APP_BUCKET.get("local-image", {});
const imageBuffer = await image?.arrayBuffer();
const imageBase64 = btoa(String.fromCharCode(...new Uint8Array(imageBuffer)));
const imageUrl = `data:image/png;base64,${imageBase64}`;
Display images from r2 the easy way.
- Makes your r2 bucket public and get a
r2.dev
domain - https://developers.cloudflare.com/r2/buckets/public-buckets/#managed-public-buckets-through-r2dev - get images by supplying the key in the subpath of your r2.dev URL e.g
https://pub-example-bucket.r2.dev/${r2-image-key}
note: link your custom domain is the preferred method when going to prod as you can use existing Cloudflare caching - https://developers.cloudflare.com/r2/buckets/public-buckets/#custom-domains
transform images with a Cloudflare images and their URL API: https://developers.cloudflare.com/images/transform-images/transform-via-url/
note: you must have a domain to be able to do this, once enable it exposes a sub path cdn-cgi
on your domain a.k.a zone e.g
https://chiubaca.com/cdn-cgi/image/width=80,quality=75/https://assets.chiubaca.com/PxcxZE6aGI_kLOEM6gq_400x400.jpg