astro-loader-s3
v0.1.1
Published
Astro content loader for S3-compatible object storage
Downloads
12
Maintainers
Readme
astro-loader-s3
An Astro content loader for loading Markdown files from AWS S3 and S3-compatible object storage (Cloudflare R2, DigitalOcean Spaces, etc.).
Installation
npm install astro-loader-s3Usage
Add the loader to your Astro content collection in src/content/config.ts:
import { defineCollection } from 'astro:content';
import { s3Loader } from 'astro-loader-s3';
const posts = defineCollection({
loader: s3Loader({
bucket: 'my-bucket',
prefix: 'posts',
accessKeyId: import.meta.env.AWS_ACCESS_KEY_ID,
secretAccessKey: import.meta.env.AWS_SECRET_ACCESS_KEY,
}),
schema: z.object({
title: z.string(),
date: z.coerce.date(),
// ... add more fields as needed
}),
});
export const collections = { posts };Options
Required
bucket(string) — The S3 bucket name to load from.accessKeyId(string) — AWS access key ID or equivalent credentials.secretAccessKey(string) — AWS secret access key or equivalent credentials.
Optional
prefix(string) — Key prefix to scope which objects are loaded (e.g.,"posts"). Omit to load the entire bucket.endpoint(string) — Custom endpoint URL for S3-compatible providers. Examples:- Cloudflare R2:
https://<account_id>.r2.cloudflarestorage.com - DigitalOcean Spaces:
https://<region>.digitaloceanspaces.com - Omit for AWS S3.
- Cloudflare R2:
region(string, default:"auto") — AWS region. For AWS S3, set your bucket's region, e.g.,"us-east-1".
