Minima.js API / @minimajs/disk / plugins / storeAs
Function: storeAs()
ts
function storeAs(strategy?): (disk) => void;storeAs plugin — customize how filenames are generated when a File object is passed to put.
By default, disk.put(file) uses the file's original name as-is. Use this plugin to automatically rename uploaded files using a UUID strategy or a custom generator.
"uuid"— generates a UUID filename, preserving the extension:550e8400.jpg"uuid-original"— prefixes the UUID before the original name:550e8400-photo.jpg- custom function — full control over the generated name (sync or async)
When the name is changed, the original filename is preserved in file.metadata.originalName.
Parameters
strategy?
Returns
ts
(disk): void;Parameters
disk
Returns
void
Examples
ts
// UUID filename (default strategy)
const disk = createDisk({ driver }, storeAs())
await disk.put(new File(['…'], 'photo.jpg')) // stored as "550e8400-….jpg"ts
// UUID prefix + original name
const disk = createDisk({ driver }, storeAs("uuid-original"))
await disk.put(new File(['…'], 'photo.jpg')) // stored as "550e8400-…-photo.jpg"ts
// Custom generator — year-based path
const disk = createDisk({ driver }, storeAs(file => `${new Date().getFullYear()}/${randomUUID()}${extname(file.name)}`))ts
// Async custom generator — content hash
const disk = createDisk({ driver }, storeAs(async file => {
const hash = await sha256(await file.arrayBuffer());
return `${hash}${extname(file.name)}`;
}))