Nuxt Blob Storage

Setup Blob Storage in your Nuxt application to store assets like images, videos, documents. Compatible with AWS S3, Cloudflare R2, Vercel Blob and more.

Getting Started

Enable blob storage

Enable blob storage in your project by setting blob: true in the NuxtHub config.

nuxt.config.ts
export default defineNuxtConfig({
  hub: {
    blob: true
  }
})

Set a driver

NuxtHub automatically configures the blob storage driver based on your environment variables or hosting provider.

By default, if NuxtHub cannot detect a driver, files are stored locally in the .data/blob directory.

To set the storage directory, you can set the dir option.

nuxt.config.ts
export default defineNuxtConfig({
  hub: {
    blob: {
      driver: 'fs',
      dir: '.data/my-blob-directory' // Defaults to `.data/blob`
    }
  }
})
The local filesystem driver is not suitable for production environments.

Upload a file

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)
Learn how to upload files with validation and progress tracking.

Driver options

You can set a custom driver by providing a configuration object to blob.

nuxt.config.ts
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'
    }
  }
})

Nuxt Image Integration

@nuxt/image provides automatic image optimization. You can combine it with blob storage to serve optimized images from your storage.

Install @nuxt/image

Terminal
npx nuxt module add image
This command will install @nuxt/image and add it to your modules section of your nuxt.config.ts.

Configure the image provider

Configure @nuxt/image to use the appropriate provider for your hosting platform:

nuxt.config.ts
export default defineNuxtConfig({
  image: {
    provider: 'cloudflare',
    cloudflare: { baseURL: '/images' }
  }
})
See Cloudflare provider docs for requirements and options.

Use NuxtImg or NuxtPicture

Use the components to display optimized images from blob storage:

pages/gallery.vue
<template>
  <NuxtImg src="/images/photo.jpg" width="300" quality="80" />
</template>

The src path combines your route prefix (/images) with the blob pathname (photo.jpg).