Skip to main content

Disk Storage

Introduction

The Disk Storage Engine automatically is used by default to store files on your system. By default it stores files in {rootDir}/tmp/uploads/{hash}-{originalFileName}

Usage

The Disk Storage Engine is enabled by default, but can be configured to custom needs.

Customising the Engine

You can add options to the disk storage engine creating a new diskEngine

const customDiskEngine = diskEngine({
// Alternative specification
// destination: './tmp/uploads',
destination: (req,file,cb) => {
return cb(null,'/tmp/uploads')
},
filename: (req,file,cb) => {
const randomHash = crypto.randomBytes(16).toString()
return cb(null, randomHash + '-' + file.originalname)
}
})

Caveats

The Disk Storage Engine should not be used in production, because as a principle backend instances should be stateless to allow for easier horizontal scaling.

Hence, to keep the development and testing environments more consistent with the production environment, an S3 Engine or another cloud storage engine should be used instead.