-
Notifications
You must be signed in to change notification settings - Fork 1
storage HowTo
GitHub Action edited this page Apr 21, 2026
·
1 revision
This guide covers the basic operations for managing files via the Quatrain storage abstraction.
Before interacting with files, configure the Storage registry with your chosen adapter.
import { Storage } from '@quatrain/storage'
import { S3Adapter } from '@quatrain/storage-s3'
const adapter = new S3Adapter({
config: {
accesskey: process.env.S3_KEY,
secret: process.env.S3_SECRET,
region: 'eu-central-1',
endpoint: 'https://s3.eu-central-1.amazonaws.com'
}
})
Storage.addAdapter('default', adapter, true)You can upload files using raw buffers or file paths, depending on the adapter's capabilities.
import { Storage } from '@quatrain/storage'
async function uploadAvatar(userId: string, imageBuffer: Buffer) {
const storage = Storage.getAdapter() // Gets the default adapter
// put(bucket, path, data, options)
await storage.put('user-avatars', `${userId}/avatar.png`, imageBuffer, {
contentType: 'image/png'
})
console.log('Upload complete!')
}Often, you just need a public URL to serve the file to a frontend client.
import { Storage } from '@quatrain/storage'
async function getAvatarUrl(userId: string) {
const storage = Storage.getAdapter()
try {
// getUrl returns a fully qualified public URL
const url = await storage.getUrl('user-avatars', `${userId}/avatar.png`)
return url
} catch (err) {
console.error('File not found')
return null
}
}