Skip to main content

Storage

NaijaBase Storage lets you store files — images, videos, PDFs, documents — in buckets hosted in Lagos, Nigeria. The API is S3-compatible, so existing S3 libraries work with minimal changes.

Upload a file

// From a browser file input
const file = event.target.files[0]

const { data, error } = await naijabase
.storage
.from('avatars')
.upload(`users/${userId}.jpg`, file, {
contentType: 'image/jpeg',
})

Get a public URL

const { publicUrl } = naijabase
.storage
.from('avatars')
.getPublicUrl(`users/${userId}.jpg`)

// publicUrl is a string — use it directly in <img src={publicUrl} />

Download a file

const { data, error } = await naijabase
.storage
.from('documents')
.download('contract.pdf')

// data is a Blob — create an object URL or save it
const url = URL.createObjectURL(data)

List files in a folder

const { data, error } = await naijabase
.storage
.from('avatars')
.list('users/')

// data is an array of { name, id, metadata } objects

Delete files

const { error } = await naijabase
.storage
.from('avatars')
.remove(['users/old-avatar.jpg', 'users/temp.jpg'])

Bucket naming

Buckets group related files together. Common patterns:

BucketContents
avatarsUser profile photos
documentsPDFs, contracts, invoices
mediaImages and videos for your app
uploadsGeneral user uploads

Data residency

All files stored in NaijaBase Storage are physically located at Rack Centre, Victoria Island, Lagos, Nigeria. Files never leave Nigeria. This satisfies NDPA 2023 requirements for personal data localization.

S3 compatibility

NaijaBase Storage exposes an S3-compatible API. Your project Storage URL is on the API tab of your project dashboard. Use it with any S3-compatible client.