Enable blob storage in your project by setting blob: true in the NuxtHub config.
export default defineNuxtConfig({
hub: {
blob: true
}
})
NuxtHub automatically configures the blob storage driver based on your environment variables or hosting provider.
.data/blob directory.To set the storage directory, you can set the dir option.
export default defineNuxtConfig({
hub: {
blob: {
driver: 'fs',
dir: '.data/my-blob-directory' // Defaults to `.data/blob`
}
}
})
To configure Amazon S3 as a blob storage driver.
aws4fetch packagepnpm add aws4fetch
yarn add aws4fetch
npm install aws4fetch
bun add aws4fetch
deno add npm:aws4fetch
npx nypm add aws4fetch
S3_ACCESS_KEY_ID=your-access-key-id
S3_SECRET_ACCESS_KEY=your-secret-access-key
S3_BUCKET=your-bucket-name
S3_REGION=your-region
S3_ENDPOINT=your-endpoint # (optional)
When deploying to Vercel, it automatically configures Vercel Blob Storage.
@vercel/blob packagepnpm add @vercel/blob
yarn add @vercel/blob
npm install @vercel/blob
bun add @vercel/blob
deno add npm:@vercel/blob
npx nypm add @vercel/blob
BLOB_READ_WRITE_TOKEN environment variable to enable the Vercel Blob driver:BLOB_READ_WRITE_TOKEN=your-token
When deploying to Cloudflare, configure Cloudflare R2 by providing the bucket name. NuxtHub auto-generates the wrangler bindings at build time.
export default defineNuxtConfig({
hub: {
blob: {
driver: 'cloudflare-r2',
bucketName: '<bucket-name>'
}
}
})
To upload a file, you can use the blob.put() method.
import { blob } from 'hub:blob'
const file = await blob.put('avatars/user-1.png', imageData)
You can set a custom driver by providing a configuration object to blob.
export default defineNuxtConfig({
hub: {
blob: {
driver: 'fs',
dir: '.data/blob'
}
},
// or overwrite only in production
$production: {
hub: {
blob: {
driver: 'vercel-blob'
}
}
}
})
Available drivers:
export default defineNuxtConfig({
hub: {
blob: {
driver: 'fs',
dir: '.data/files' // defaults to '.data/blob'
}
}
})
export default defineNuxtConfig({
hub: {
blob: {
driver: 's3',
accessKeyId: 'your-access-key-id', // defaults to S3_ACCESS_KEY_ID
secretAccessKey: 'your-secret-access-key', // defaults to S3_SECRET_ACCESS_KEY
bucket: 'your-bucket-name', // defaults to S3_BUCKET
region: 'your-region', // defaults to S3_REGION or 'auto'
endpoint: 'your-endpoint' // optional, defaults to S3_ENDPOINT
}
}
})
export default defineNuxtConfig({
hub: {
blob: {
driver: 'vercel-blob',
token: 'your-token' // optional, defaults to BLOB_READ_WRITE_TOKEN env var
}
}
})
export default defineNuxtConfig({
hub: {
blob: {
driver: 'cloudflare-r2',
binding: 'BLOB' // optional, defaults to 'BLOB'
}
}
})