Page:
storage HowTo
Pages
Home
ai Overview
ai gemini Overview
api HowTo
api Overview
api client HowTo
api client Overview
api server HowTo
api server Overview
api server express HowTo
app HowTo
app Overview
auth HowTo
auth Overview
auth basic HowTo
auth basic Overview
auth firebase HowTo
auth firebase Overview
auth oidc Overview
auth pocketbase HowTo
auth pocketbase Overview
auth supabase HowTo
auth supabase Overview
backend HowTo
backend Overview
backend firestore Overview
backend migrations Overview
backend postgres Overview
backend restapi Overview
backend restapi recipes Overview
backend sqlite HowTo
backend sqlite Overview
cache Overview
cache redis Overview
cloudwrapper HowTo
cloudwrapper Overview
cloudwrapper firebase HowTo
cloudwrapper firebase Overview
cloudwrapper supabase HowTo
cloudwrapper supabase Overview
code Overview
code github Overview
core HowTo
core Overview
core cli HowTo
core cli Overview
gateway upstream express HowTo
gateway upstream express Overview
i18n HowTo
i18n Overview
i18n en HowTo
i18n en Overview
i18n fr HowTo
i18n fr Overview
log HowTo
log Overview
messaging HowTo
messaging Overview
messaging firebase HowTo
messaging firebase Overview
queue HowTo
queue Overview
queue amqp HowTo
queue amqp Overview
queue aws HowTo
queue aws Overview
queue gcp HowTo
queue gcp Overview
storage HowTo
storage Overview
storage firebase HowTo
storage firebase Overview
storage local Overview
storage s3 HowTo
storage s3 Overview
storage supabase HowTo
storage supabase Overview
studio Overview
testing Overview
types HowTo
types Overview
ui Overview
ui form react Overview
ui list HowTo
ui list Overview
ui list react HowTo
ui list react Overview
worker HowTo
worker Overview
No results
3
storage HowTo
GitHub Action edited this page 2026-05-21 08:10:54 +00:00
How To: Using @quatrain/storage
This guide covers the basic operations for managing files via the Quatrain storage abstraction.
Table of Contents
1. Registering a Storage Adapter
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)
2. Uploading Files
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!')
}
3. Retrieving Files and URLs
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({ bucket: 'user-avatars', ref: `${userId}/avatar.png` })
return url
} catch (err) {
console.error('File not found')
return null
}
}
4. Fetching Bucket Statistics
You can fetch summary statistics for a bucket, optionally filtering by a key prefix (which allows analyzing a specific subdirectory hierarchy).
import { Storage } from '@quatrain/storage'
async function getCompanyStorageStats(companyId: string) {
const storage = Storage.getAdapter()
// getBucketStats(bucket, prefix)
const stats = await storage.getBucketStats('company-documents', `companies/${companyId}`)
console.log(`Total objects under prefix: ${stats.totalObjects}`)
console.log(`Total storage size: ${stats.totalSize} bytes`)
console.log(`Last modified timestamp: ${stats.lastModified}`)
console.log(`Raw objects list:`, stats.objects)
}
Core Documentation
Foundations
Storage, Data & Cache
- backend
- backend-firestore
- backend-postgres
- backend-sqlite
- backend-migrations
- storage
- storage-firebase
- storage-s3
- storage-supabase
- storage-local
- cache
- cache-redis
Queue & Messaging
Auth & Cloud
- auth
- auth-firebase
- auth-supabase
- auth-oidc
- auth-pocketbase
- cloudwrapper
- cloudwrapper-firebase
- cloudwrapper-supabase