File Adapters

Install dependencies:

npm install @aws-sdk/client-s3 --save

S3 (Amazon Example)

Within @/config.js

import defineConfig from '@/lib/config/defineConfig'
import fileAdapters from '@/lib/file/adapter'

export default defineConfig({
    file: {
        defaultAdapter: 'file',
        adapters: [
            fileAdapters.s3({
                id: 's3', // default
                mode: ['live', 'test'],
                accessKeyId: process.env.S3_BUCKET_ACCESS_KEY_ID,
                secretAccessKey: process.env.S3_BUCKET_SECRET_ACCESS_KEY,
                name: process.env.S3_BUCKET_NAME || 'bucket-name',
                endpoint: process.env.S3_BUCKET_ENDPOINT || 'bucket-name.s3.amazonaws.com',
                cdn: process.env.S3_BUCKET_CDN || 'https://cdn-id.cloudfront.net',
            })
        ]
    }
})

S3 (Digital Ocean Spaces)

Within @/config.js

import defineConfig from '@/lib/config/defineConfig'
import fileAdapters from '@/lib/file/adapter'

export default defineConfig({
    file: {
        defaultAdapter: 'file',
        adapters: [
            fileAdapters.s3({
                id: 's3', // default
                mode: ['live', 'test'],
                accessKeyId: process.env.S3_BUCKET_ACCESS_KEY_ID,
                secretAccessKey: process.env.S3_BUCKET_SECRET_ACCESS_KEY,
                name: process.env.S3_BUCKET_NAME || 'bucket-name',
                endpoint: process.env.S3_BUCKET_ENDPOINT || 'ams3.digitaloceanspaces.com',
                cdn: process.env.S3_BUCKET_CDN || 'https://cdn.createnextstartup.com',
            })
        ]
    }
})

Local File System

Within @/config.js

import defineConfig from '@/lib/config/defineConfig'
import fileAdapters from '@/lib/file/adapter'

export default defineConfig({
    file: {
        defaultAdapter: 's3',
        adapters: [
            fileAdapters.fs({
                id: 'fs', // default
                mode: ['live', 'test'],
                uploadPath: '/public/uploads'
            }),
        ]
    }
})

Roadmap

  • TODO: Show "how to create a custom file adapter yourself"