Multiple disks
Register several disks and route collections (or individual uploads) to the right one.
A real app often wants more than one disk — a fast public CDN bucket for images, a private bucket for documents, local disk in dev. StorageModule holds any number of named disks; media routes per collection or per call.
Register them
StorageModule.forRoot({
default: 's3',
disks: {
s3: new S3Disk({ bucket: 'public-assets', publicUrl: 'https://cdn…' }),
private: new S3Disk({ bucket: 'private-docs' }),
local: new LocalDisk({ root: './storage' }),
},
});
MediaModule.forRoot({ store });StorageModule's default is the disk a collection uses unless it overrides. url() gives CDN URLs on s3 and signed ones on private.
Route by collection
Pin a collection to a disk with the disk option:
collections: [
{ name: 'gallery', disk: 's3' }, // public images → CDN bucket
{ name: 'invoices', disk: 'private' }, // private docs → private bucket
]Now attach to invoices lands in the private bucket automatically; gallery goes to the public one.
Route per upload
Override per call when you need to — the precedence is per-call → collection → module default:
await media.library.attach({
ownerType: 'Post', ownerId: '1', collection: 'gallery',
fileName, mimeType, contents,
disk: 'local', // this one upload goes local regardless of the collection's disk
});Moving files between disks
A disk's copy/move stay on that disk. Across disks, stream one into the other:
const source = await storage.disk('local').get(key);
await storage.disk('s3').put(key, source.body, { contentType: source.contentType, contentLength: source.size });The console does this for cross-disk copies and moves, folders included.
Conversions are written to the same disk as their original, so a private collection's variants stay private too.
Upload behavior also follows the disk: a disk with a multipart side-car (or that presigns) defaults to the direct path, a local disk to proxy — each overridable via uploadMode.