---
title: File storage
project: Total.js V4
version: 0.0.99
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/total-js-v4/0-0-99/reference/file-storage/
updated: 2026-11-16T15:41:20.819Z
---

# File storage

> FILESTORAGE(), its methods, the meta object and the controller methods that serve stored files.

`FILESTORAGE(name)` returns a storage of binary files in `databases/fs-{name}/`. In this reference `fs` is a storage returned by `FILESTORAGE()` and `meta` the metadata of a file. The guide [File storage](../../guides/file-storage/) explains how to save, read and serve files with examples.

## API

### FILESTORAGE(name)

Type: `method`

Returns a file storage.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the storage. |

Returns: `FileStorage` The storage.

Returns the storage `name`, stored in `databases/fs-{name}/`. The object is created on the first call and reused later. The folder is created when the first file is saved.

Example: Get a storage
```js
var fs = FILESTORAGE('photos');
fs.save(UID(), 'logo.png', PATH.public('img/logo.png'));
```

### PATH.filestorage(name)

Type: `method`

Returns the folder of a file storage.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the storage. |

Returns: `String` The absolute path of the folder.

Returns the path `databases/fs-{name}/` inside the folder set by `directory_databases`.

Example: Folder
```js
console.log(PATH.filestorage('photos'));
// /www/app/databases/fs-photos/
```

### fs.name

Type: `property`

The name of the storage.

Returns: `String`

The name given to `FILESTORAGE()`.

Example: Name
```js
console.log(FILESTORAGE('photos').name); // photos
```

### fs.directory

Type: `property`

The folder of the storage.

Returns: `String`

The absolute path of the folder with the files. Change it with `fs.storage()`.

Example: Folder
```js
console.log(FILESTORAGE('photos').directory);
```

### fs.total

Type: `property`

The number of files.

Returns: `Number`

A counter kept in memory. It starts at `0`; `fs.count()` and `fs.rebuild()` set it, and every saved file adds one.

Example: Load the counters
```js
var fs = FILESTORAGE('photos');
fs.count(function() {
	console.log(fs.total, fs.size);
});
```

### fs.size

Type: `property`

The total size of the files in bytes.

Returns: `Number`

A counter kept in memory. It starts at `0`; `fs.count()` and `fs.rebuild()` set it, and every saved file adds its size.

Example: Size in MB
```js
var fs = FILESTORAGE('photos');
fs.count(function() {
	console.log((fs.size / 1024 / 1024).floor(2) + ' MB');
});
```

### fs.save(id, name, data, [callback], [custom], [expire], [headers])

Type: `method`

Saves a file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | The ID of the file. |
| `name` | `String` | yes |  | The file name with its extension. |
| `data` | `String|Buffer|Stream` | yes |  | A path, a buffer, a readable stream or a URL. |
| `callback` | `Function` | no |  | `function(err, meta)`, runs when the file is saved. |
| `custom` | `Object` | no |  | Any data kept with the file as `meta.custom`. |
| `expire` | `String` | no |  | A period such as `'1 day'`; after it the file cannot be read. |
| `headers` | `Object` | no |  | Headers for the request when `data` is a URL. |

Returns: `FileStorage|Promise` The storage, or a promise with the meta object.

Stores `data` under `id`. The extension of `name` sets the content type; a path in `name` is reduced to the file name. `data` is a path to a file, a `Buffer`, a readable stream or an `http://`/`https://` URL, which is downloaded first. For GIF, PNG, JPEG and SVG images the metadata also gets `width` and `height`. An existing file with the same ID is overwritten. Without a callback the method returns a promise. Alias: `fs.insert()`.

Example: Save a buffer
```js
FILESTORAGE('documents').save(UID(), 'note.txt', Buffer.from('Hello'), function(err, meta) {
	console.log(meta.id, meta.size);
});
```

Example: Download from a URL
```js
var meta = await FILESTORAGE('photos').save(UID(), 'photo.jpg', 'https://example.com/photo.jpg', null, { source: 'web' }, '30 days');
```

### fs.insert(id, name, data, [callback], [custom], [expire], [headers])

Type: `method`

Alias of fs.save().

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | The ID of the file. |
| `name` | `String` | yes |  | The file name with its extension. |
| `data` | `String|Buffer|Stream` | yes |  | A path, a buffer, a readable stream or a URL. |
| `callback` | `Function` | no |  | `function(err, meta)`. |
| `custom` | `Object` | no |  | Any data kept with the file. |
| `expire` | `String` | no |  | An expiration period. |
| `headers` | `Object` | no |  | Headers for a URL request. |

Returns: `FileStorage|Promise` The storage, or a promise with the meta object.

The same method as `fs.save()`.

Example: Insert
```js
FILESTORAGE('documents').insert(UID(), 'a.txt', Buffer.from('A'));
```

### fs.savejson(id, value, [callback], [custom], [expire])

Type: `method`

Saves an object as JSON.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | The ID of the file. |
| `value` | `Object` | yes |  | The value to store. |
| `callback` | `Function` | no |  | `function(err, meta)`. |
| `custom` | `Object` | no |  | Any data kept with the file. |
| `expire` | `String` | no |  | An expiration period. |

Returns: `FileStorage|Promise` The storage, or a promise without a callback.

Serializes `value` with `JSON.stringify()` and saves it as `{id}.json`.

Example: Save settings
```js
FILESTORAGE('data').savejson('settings', { theme: 'dark' });
```

### fs.read(id, [callback], [nostream])

Type: `method`

Reads a file as a stream.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | The ID of the file. |
| `callback` | `Function` | no |  | `function(err, meta)`. |
| `nostream` | `Boolean` | no | `false` | Do not open a stream of the content. |

Returns: `FileStorage|Promise` The storage, or a promise with the meta object.

Gives the meta object with `meta.stream`, a readable stream of the content. With `nostream` set to `true` the meta object comes without the stream. Errors: `File not found`, `Invalid file`, `File is expired` or an error of the file system. Without a callback the method returns a promise.

Example: Pipe to a file
```js
FILESTORAGE('documents').read(id, function(err, meta) {
	if (!err)
		meta.stream.pipe(F.Fs.createWriteStream(PATH.temp(meta.name)));
});
```

### fs.readmeta(id, [callback], [keepfd])

Type: `method`

Reads only the metadata of a file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | The ID of the file. |
| `callback` | `Function` | no |  | `function(err, meta, filename, fd)`. |
| `keepfd` | `Boolean` | no | `false` | Keep the file descriptor `fd` open; you must close it. |

Returns: `FileStorage|Promise` The storage, or a promise with the meta object.

Reads the header of the file. Dates come as `Date` objects. The callback also gets the path of the file on the disk. Unlike `fs.read()`, it does not check the expiration. Without a callback the method returns a promise.

Example: Metadata
```js
FILESTORAGE('documents').readmeta(id, function(err, meta) {
	console.log(meta.name, meta.type, meta.size);
});
```

### fs.readbuffer(id, [callback])

Type: `method`

Reads the content of a file into a Buffer.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | The ID of the file. |
| `callback` | `Function` | no |  | `function(err, buffer, meta)`. |

Returns: `FileStorage|Promise` The storage, or a promise with the buffer.

Reads the whole file into memory. Use `fs.read()` for big files. Without a callback the method returns a promise. The promise gives only the buffer.

Example: Buffer
```js
var buffer = await FILESTORAGE('documents').readbuffer(id);
```

### fs.readbase64(id, [callback])

Type: `method`

Reads the content of a file as Base64.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | The ID of the file. |
| `callback` | `Function` | no |  | `function(err, base64, meta)`. |

Returns: `FileStorage|Promise` The storage, or a promise with the string.

Reads the whole file and encodes it as a Base64 string. Without a callback the method returns a promise. The promise gives only the string.

Example: Data URI
```js
FILESTORAGE('photos').readbase64(id, function(err, base64, meta) {
	var uri = 'data:' + meta.type + ';base64,' + base64;
});
```

### fs.readjson(id, callback)

Type: `method`

Reads a JSON file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | The ID of the file. |
| `callback` | `Function` | yes |  | `function(err, value, meta)`. |

Returns: `FileStorage` The storage.

Reads a file saved by `fs.savejson()` and parses it. The callback is required.

Example: Read settings
```js
FILESTORAGE('data').readjson('settings', function(err, value) {
	console.log(value.theme);
});
```

### fs.image(id, [callback])

Type: `method`

Reads a stored picture as an Image.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | The ID of the file. |
| `callback` | `Function` | no |  | `function(err, image, meta)`. |

Returns: `FileStorage|Promise` The storage, or a promise with the image.

Gives an `Image` object that reads the content of the file, so you can resize or convert it and save the result. Image processing needs GraphicsMagick or ImageMagick. Without a callback the method returns a promise. The promise gives only the image.

Example: Thumbnail
```js
FILESTORAGE('photos').image(id, function(err, image, meta) {
	if (err)
		return;
	image.resize(200, 200);
	image.save(PATH.temp('thumb_' + meta.name));
});
```

### fs.res(res, options, [checkmeta])

Type: `method`

Sends a file to an HTTP response.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `res` | `Response` | yes |  | The response object. |
| `options` | `Object` | yes |  | The options, see above. |
| `checkmeta` | `Function` | no |  | `function(meta)`; return `false` to answer with `404`. |

Returns: `undefined`

The method behind `controller.filefs()` and `controller.imagefs()`. `options`: `id` (the file), `download` (`true` for the stored name, a string, or `function(name, type)` that returns the name), `headers`, `done` (a callback), `nocompress`, and for images `image: true`, `make` (`function(image, res)`) and `cache` (default `true`). It supports `If-Modified-Since` (`304`) and `Range` requests (`206`). A missing or expired file, or `checkmeta(meta)` that returns `false`, gives `404`.

Example: In a route with req and res
```js
ROUTE('GET /files/{id}/', function(id) {
	FILESTORAGE('documents').res(this.res, { id: id, download: true });
});
```

### fs.copy(id, path, [callback])

Type: `method` · Since: `0.0.97`

Copies the content of a file to the disk.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | The ID of the file. |
| `path` | `String` | yes |  | A target file, or a folder. |
| `callback` | `Function` | no |  | `function(err, meta)`. |

Returns: `FileStorage|Promise` The storage, or a promise with the meta object.

Writes the content of the file (without the header) to `path`. A path with a dot is used as the file name; any other path is a folder and the file keeps its stored name. The folder must exist. Expired files give the error `File is expired`. Without a callback the method returns a promise.

Example: Export to a folder
```js
FILESTORAGE('documents').copy(id, PATH.temp(), function(err, meta) {
	console.log(PATH.temp(meta.name));
});
```

Example: Export to a file
```js
await FILESTORAGE('documents').copy(id, PATH.temp('invoice.pdf'));
```

### fs.clone(id, [newid], [callback])

Type: `method` · Since: `0.0.99`

Copies a file inside the storage under a new ID.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | The ID of the file. |
| `newid` | `String` | no | `UID()` | The ID of the copy. |
| `callback` | `Function` | no |  | `function(err, meta)`; `meta.id` is the new ID. |

Returns: `FileStorage|Promise` The storage, or a promise with the meta object.

Creates a copy of the file with the same metadata under `newid` and adds it to `files.log`. When the second argument is the callback, a new ID is generated with `UID()`. Expired files give the error `File is expired`. Without a callback the method returns a promise. In the promise form pass `newid`.

Example: Clone
```js
FILESTORAGE('documents').clone(id, function(err, meta) {
	console.log('Copy:', meta.id);
});
```

Example: Clone as a promise
```js
var meta = await FILESTORAGE('documents').clone(id, UID());
```

### fs.move(id, newid, [callback])

Type: `method`

Changes the ID of a file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | The ID of the file. |
| `newid` | `String` | yes |  | The new ID. |
| `callback` | `Function` | no |  | `function(err)`. |

Returns: `FileStorage|Promise` The storage, or a promise.

Moves the file to the name and folder of `newid`. `files.log` is not changed; call `fs.rebuild()` when you list files with `fs.browse()`. Without a callback the method returns a promise.

Example: Move
```js
FILESTORAGE('documents').move('draft', 'final', function(err) {
	console.log(err ? 'Error' : 'Moved');
});
```

### fs.rename(id, newname, [callback])

Type: `method`

Changes the stored name of a file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | The ID of the file. |
| `newname` | `String` | yes |  | The new file name (at most 250 characters). |
| `callback` | `Function` | no |  | `function(err, meta)`. |

Returns: `FileStorage|Promise` The storage, or a promise with the meta object.

Writes the new name into the header and into `files.log`. The content type stays the same. Without a callback the method returns a promise.

Example: Rename
```js
FILESTORAGE('documents').rename(id, 'contract-2024.pdf');
```

### fs.remove(id, [callback])

Type: `method`

Removes a file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | The ID of the file. |
| `callback` | `Function` | no |  | `function(err)`. |

Returns: `FileStorage|Promise` The storage, or a promise.

Deletes the file from the disk and from `files.log`. Without a callback the method returns a promise.

Example: Remove
```js
FILESTORAGE('documents').remove(id, function(err) {
	console.log(err ? 'Not found' : 'Removed');
});
```

### fs.browse([callback])

Type: `method`

Lists files from files.log.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | `function(err, files)`. |

Returns: `QueryBuilder` The query builder.

Returns a NoSQL query builder over `files.log`, the database with the metadata of all files. Add conditions, sorting and paging, then `callback()`.

Example: Latest images
```js
FILESTORAGE('photos').browse().where('ext', 'jpg').sort('date_desc').take(10).callback(function(err, files) {
	console.log(files);
});
```

### fs.browse2([callback])

Type: `method`

Lists files from the disk.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | `function(err, files)`. |

Returns: `FileStorage|Promise` The storage, or a promise with the array.

Reads the header of every file on the disk and returns their meta objects. Slower than `fs.browse()`, but it does not depend on `files.log`. Without a callback the method returns a promise.

Example: All files
```js
var files = await FILESTORAGE('photos').browse2();
console.log(files.length);
```

### fs.stream(onfile, [callback], [workers])

Type: `method`

Goes through all files on the disk one by one.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `onfile` | `Function` | yes |  | `function(meta, next)`. |
| `callback` | `Function` | no |  | Runs when all files are processed. |
| `workers` | `Number` | no |  | How many files are processed at the same time. |

Returns: `FileStorage` The storage.

Calls `onfile(meta, next)` for every file; call `next()` to continue. `meta.index` is the order of the file. `callback` runs at the end.

Example: Find big files
```js
FILESTORAGE('documents').stream(function(meta, next) {
	if (meta.size > 1024 * 1024 * 10)
		console.log(meta.id, meta.name);
	next();
}, function() {
	console.log('Done');
});
```

### fs.count([callback])

Type: `method`

Counts files and their size from files.log.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | `function(err, response)`. |

Returns: `FileStorage` The storage.

Gives an object with `count` (the number of files) and `size` (the total size in bytes), and updates `fs.total` and `fs.size`.

Example: Count
```js
FILESTORAGE('photos').count(function(err, response) {
	console.log(response.count, response.size);
});
```

### fs.count2([callback])

Type: `method`

Counts files on the disk.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | `function(err, count)`. |

Returns: `FileStorage|Promise` The storage, or a promise with the number.

Counts the files in the subfolders of the storage, without `files.log`. Without a callback the method returns a promise.

Example: Count on disk
```js
var count = await FILESTORAGE('photos').count2();
```

### fs.rebuild([callback])

Type: `method`

Creates files.log again from the files on the disk.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | Runs when the log is written. |

Returns: `FileStorage|Promise` The storage, or a promise.

Reads all files with `fs.browse2()`, writes a new `files.log` and sets `fs.total` and `fs.size`. Use it after `fs.move()` or when `files.log` was lost. Without a callback the method returns a promise.

Example: Rebuild
```js
FILESTORAGE('photos').rebuild(function() {
	console.log('files.log is ready');
});
```

### fs.clean([callback])

Type: `method`

Removes expired files.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | `function(err, count)`; `count` is the number of removed files. |

Returns: `FileStorage|Promise` The storage, or a promise with the number.

Finds files whose `expire` date has passed in `files.log` and deletes them. Without a callback the method returns a promise.

Example: Clean every day
```js
ON('service', function(counter) {
	if (counter % 1440 === 0)
		FILESTORAGE('temporary').clean();
});
```

### fs.clear([callback])

Type: `method`

Removes all files.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | `function(err, count)`; `count` is the number of removed files. |

Returns: `FileStorage|Promise` The storage, or a promise with the number.

Deletes all files, their subfolders and `files.log`. While it runs, other reads and saves wait. Without a callback the method returns a promise. Alias: `fs.drop()`.

Example: Clear
```js
var count = await FILESTORAGE('temporary').clear();
```

### fs.drop([callback])

Type: `method`

Alias of fs.clear().

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | `function(err, count)`. |

Returns: `FileStorage|Promise` The storage, or a promise with the number.

The same method as `fs.clear()`.

Example: Drop
```js
FILESTORAGE('temporary').drop();
```

### fs.backup(filename, [callback])

Type: `method`

Writes all files into one backup file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String|Stream` | yes |  | The target file or a writable stream. |
| `callback` | `Function` | no |  | `function(err, response)`; `response` has `filename`, `files` and `size`. |

Returns: `FileStorage|Promise` The storage, or a promise with the response.

Each file is compressed with GZIP and written as Base64. `filename` is a path or a writable stream. Without a callback the method returns a promise.

Example: Backup
```js
FILESTORAGE('photos').backup(PATH.temp('photos.backup'), function(err, response) {
	console.log(response.files, response.size);
});
```

### fs.restore(filename, [callback])

Type: `method`

Restores the storage from a backup file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String` | yes |  | The backup file. |
| `callback` | `Function` | no |  | `function(err, meta)`. |

Returns: `FileStorage|Promise` The storage, or a promise.

Removes all current files first (like `fs.clear()`), then unpacks the backup made by `fs.backup()`. Reads and saves wait until it ends. Without a callback the method returns a promise.

Example: Restore
```js
FILESTORAGE('photos').restore(PATH.temp('photos.backup'), function(err) {
	FILESTORAGE('photos').rebuild();
});
```

### fs.storage(directory)

Type: `method`

Changes the folder of the storage.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `directory` | `String` | yes |  | The absolute path of the folder. |

Returns: `FileStorage` The storage.

Sets `fs.directory` and the path of `files.log` to another folder.

Example: Another disk
```js
FILESTORAGE('archive').storage('/mnt/archive/files/');
```

### fs.readfilename(id)

Type: `method`

Returns the path of a file on the disk.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | The ID of the file. |

Returns: `String` The absolute path.

Returns the path of the `.file` for `id`. The file starts with a header of 2000 bytes, so it is not a copy of the original file; use `fs.copy()` for that.

Example: Path
```js
console.log(FILESTORAGE('photos').readfilename(id));
```

### controller.filefs(name, id, [download], [headers], [callback], [checkmeta])

Type: `method`

Answers with a file from a storage.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the storage. |
| `id` | `String` | yes |  | The ID of the file. |
| `download` | `Boolean|String|Function` | no |  | `true`, a file name, or `function(name, type)` that returns the name. |
| `headers` | `Object` | no |  | Extra response headers. |
| `callback` | `Function` | no |  | Runs when the file is sent. |
| `checkmeta` | `Function` | no |  | `function(meta)`; return `false` to answer with `404`. |

Returns: `Controller` The controller.

Sends the file `id` of `FILESTORAGE(name)` with its stored content type. `download` set to `true` uses the stored name, a string sets another name. `checkmeta(meta)` that returns `false` gives `404`. `Range` and `If-Modified-Since` requests are supported. The response object has the same method, `res.filefs()`.

Example: Download
```js
exports.install = function() {
	ROUTE('GET /download/{id}/', download);
};

function download(id) {
	this.filefs('documents', id, true);
}
```

### controller.imagefs(name, id, make, [headers], [callback], [checkmeta])

Type: `method`

Answers with a processed image from a storage.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | The name of the storage. |
| `id` | `String` | yes |  | The ID of the file. |
| `make` | `Function` | yes |  | `function(image, res)` that changes the image. |
| `headers` | `Object` | no |  | Extra response headers. |
| `callback` | `Function` | no |  | Runs when the image is sent. |
| `checkmeta` | `Function` | no |  | `function(meta)`; return `false` to answer with `404`. |

Returns: `Controller` The controller.

Reads the picture `id` of `FILESTORAGE(name)`, calls `make(image, res)` to process it and sends the result. The processed image is cached in the temporary folder per URL. Needs GraphicsMagick or ImageMagick. The response object has the same method, `res.imagefs()`.

Example: Thumbnail
```js
exports.install = function() {
	ROUTE('GET /thumbnails/{id}/', thumbnail);
};

function thumbnail(id) {
	this.imagefs('photos', id, function(image) {
		image.resizeCenter(200, 200);
		image.quality(80);
	});
}
```

### file.fs(storage, id, [custom], [expire], [callback])

Type: `method`

Saves an uploaded file into a storage.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `storage` | `String` | yes |  | The name of the storage. |
| `id` | `String` | yes |  | The ID of the file. |
| `custom` | `Object` | no |  | Any data kept with the file. |
| `expire` | `String` | no |  | An expiration period. |
| `callback` | `Function` | no |  | `function(err, meta)`. |

Returns: `FileStorage|Promise` The storage, or a promise with the meta object.

A method of every file in `controller.files`. It calls `FILESTORAGE(storage).save()` with the original file name and the temporary file of the upload. Without a callback it returns a promise.

Example: Upload
```js
exports.install = function() {
	ROUTE('POST /api/upload/', upload, ['upload'], 1024 * 5);
};

async function upload() {
	var file = this.files[0];
	var meta = await file.fs('documents', UID(), { user: this.user.id });
	this.json({ id: meta.id, name: meta.name });
}
```
