Storage
Lucent provides a flexible file storage system with support for local filesystem and S3.
Configuration
typescript
export default defineConfig({
storage: {
default: "local",
disks: {
local: {
type: "local",
basePath: "./storage",
},
s3: {
type: "s3",
bucket: process.env.S3_BUCKET,
region: process.env.S3_REGION,
accessKeyId: process.env.S3_ACCESS_KEY,
secretAccessKey: process.env.S3_SECRET_KEY,
},
},
},
});File Fields
Define file fields in your collections:
typescript
export const posts = defineCollection({
name: "posts",
fields: {
title: { type: "string", required: true },
// Single file
coverImage: { type: "file" },
// Multiple files
attachments: { type: "file", multiple: true },
// Specific file types
avatar: { type: "file", accept: ["image/*"] },
// With size limit (in bytes)
document: { type: "file", maxSize: 10 * 1024 * 1024 },
},
});Using Storage
typescript
// Upload a file
const file = await lucent.storage.upload(buffer, {
filename: "image.jpg",
mimeType: "image/jpeg",
disk: "s3", // optional, uses default
});
// Get file URL
const url = lucent.storage.getUrl(file.path);
// Delete a file
await lucent.storage.delete(file.path);File API
typescript
// List files in a directory
const files = await lucent.storage.list("avatars/");
// Check if file exists
const exists = await lucent.storage.exists("avatars/user.jpg");
// Copy file
await lucent.storage.copy("source.jpg", "dest.jpg");
// Move file
await lucent.storage.move("temp.jpg", "permanent.jpg");S3 Configuration
typescript
storage: {
disks: {
s3: {
type: 's3',
bucket: 'my-bucket',
region: 'us-east-1',
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
// Optional: custom endpoint for S3-compatible services
endpoint: 'https://storage.example.com',
// Optional: force path style
forcePathStyle: true
}
}
}