Skip to content

Setup large file storage

Use external file storage when your Git repository should not act as file storage, or when you need larger uploads. For example, Cloudflare Workers only allows files up to 25 MB.

This guide explains how to configure Cloudflare R2 for Administration UI uploads in LightNet.

  1. Add an R2 subscription: Open your Cloudflare account and enable R2 Object Storage if it is not already active.
  2. Create a bucket: Create a new R2 bucket for your uploaded files.
  3. Configure bucket settings: In the bucket settings, add a custom domain such as files.your-site.org. Then add a CORS policy like this:
    [
    {
    "AllowedOrigins": [
    "http://localhost:4321",
    "https://your-site.org"
    ],
    "AllowedMethods": [
    "GET", "PUT", "HEAD"
    ],
    "ExposeHeaders": ["ETag"],
    "AllowedHeaders": ["*"],
    "MaxAgeSeconds": 3000
    }
    ]
    Replace the sample origins with your real local development URL and your production site URL.
  4. Create an API token: In Cloudflare, go to R2 Object Storage, click API tokens and then Manage, then create an account API token. Set Permissions to Object Read & Write, set Specify buckets to Apply to specific buckets only, and select your bucket. Save the generated Access Key ID and Secret Access Key somewhere secure.

Add the experimental R2 file storage configuration to lightnetSveltiaAdmin(...):

astro.config.mjs
import lightnet from "lightnet"
import lightnetSveltiaAdmin from "@lightnet/sveltia-admin"
import { defineConfig } from "astro/config"
export default defineConfig({
integrations: [
lightnet({
// ...
}),
lightnetSveltiaAdmin({
experimental: {
fileStorage: {
name: "cloudflare-r2",
accessKeyId: "<your-access-key-id>",
bucket: "<your-bucket>",
accountId: "<your-account-id>",
publicUrl: "https://files.your-site.org",
},
},
}),
],
})
  • name: Must be "cloudflare-r2".
  • accessKeyId: The R2 Access Key ID for uploads.
  • bucket: The bucket name used to store uploaded files.
  • accountId: Your Cloudflare account ID.
  • publicUrl: Public base URL used for previews and downloads.
  • prefix: Optional path prefix inside the bucket, for example uploads/.