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

# Archivio di file

> FILESTORAGE(), i suoi metodi, l'oggetto meta e i metodi del controller che servono i file memorizzati.

`FILESTORAGE(name)` restituisce un archivio di file binari in `databases/fs-{name}/`. In questa reference `fs` è un archivio restituito da `FILESTORAGE()` e `meta` i metadati di un file. La guida [Archivio di file](../../guides/file-storage/) spiega con esempi come salvare, leggere e servire file.

## API

### FILESTORAGE(name)

Type: `method`

Restituisce un archivio di file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'archivio. |

Returns: `FileStorage` L'archivio.

Restituisce l'archivio `name`, memorizzato in `databases/fs-{name}/`. L'oggetto viene creato alla prima chiamata e poi riutilizzato. La cartella viene creata quando si salva il primo file.

Example: Ottenere un archivio
```js
var fs = FILESTORAGE('photos');
fs.save(UID(), 'logo.png', PATH.public('img/logo.png'));
```

### PATH.filestorage(name)

Type: `method`

Restituisce la cartella di un archivio di file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'archivio. |

Returns: `String` Il percorso assoluto della cartella.

Restituisce il percorso `databases/fs-{name}/` dentro la cartella impostata da `directory_databases`.

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

### fs.name

Type: `property`

Il nome dell'archivio.

Returns: `String`

Il nome passato a `FILESTORAGE()`.

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

### fs.directory

Type: `property`

La cartella dell'archivio.

Returns: `String`

Il percorso assoluto della cartella con i file. Modificalo con `fs.storage()`.

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

### fs.total

Type: `property`

Il numero di file.

Returns: `Number`

Un contatore tenuto in memoria. Parte da `0`; `fs.count()` e `fs.rebuild()` lo impostano, e ogni file salvato aggiunge uno.

Example: Caricare i contatori
```js
var fs = FILESTORAGE('photos');
fs.count(function() {
	console.log(fs.total, fs.size);
});
```

### fs.size

Type: `property`

La dimensione totale dei file in byte.

Returns: `Number`

Un contatore tenuto in memoria. Parte da `0`; `fs.count()` e `fs.rebuild()` lo impostano, e ogni file salvato aggiunge la sua dimensione.

Example: Dimensione 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`

Salva un file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'ID del file. |
| `name` | `String` | yes |  | Il nome del file con la sua estensione. |
| `data` | `String|Buffer|Stream` | yes |  | Un percorso, un buffer, uno stream leggibile o un URL. |
| `callback` | `Function` | no |  | `function(err, meta)`, viene eseguita quando il file è salvato. |
| `custom` | `Object` | no |  | Qualsiasi dato conservato con il file come `meta.custom`. |
| `expire` | `String` | no |  | Un periodo come `'1 day'`; trascorso questo il file non può essere letto. |
| `headers` | `Object` | no |  | Header per la richiesta quando `data` è un URL. |

Returns: `FileStorage|Promise` L'archivio, oppure una promise con l'oggetto meta.

Memorizza `data` sotto `id`. L'estensione di `name` determina il content type; un percorso in `name` viene ridotto al nome del file. `data` è un percorso di un file, un `Buffer`, uno stream leggibile o un URL `http://`/`https://`, che viene prima scaricato. Per le immagini GIF, PNG, JPEG e SVG i metadati ricevono anche `width` e `height`. Un file esistente con lo stesso ID viene sovrascritto. Senza callback il metodo restituisce una promise. Alias: `fs.insert()`.

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

Example: Scaricare da un 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 di fs.save().

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'ID del file. |
| `name` | `String` | yes |  | Il nome del file con la sua estensione. |
| `data` | `String|Buffer|Stream` | yes |  | Un percorso, un buffer, uno stream leggibile o un URL. |
| `callback` | `Function` | no |  | `function(err, meta)`. |
| `custom` | `Object` | no |  | Qualsiasi dato conservato con il file. |
| `expire` | `String` | no |  | Un periodo di scadenza. |
| `headers` | `Object` | no |  | Header per una richiesta a un URL. |

Returns: `FileStorage|Promise` L'archivio, oppure una promise con l'oggetto meta.

Lo stesso metodo di `fs.save()`.

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

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

Type: `method`

Salva un oggetto come JSON.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'ID del file. |
| `value` | `Object` | yes |  | Il valore da memorizzare. |
| `callback` | `Function` | no |  | `function(err, meta)`. |
| `custom` | `Object` | no |  | Qualsiasi dato conservato con il file. |
| `expire` | `String` | no |  | Un periodo di scadenza. |

Returns: `FileStorage|Promise` L'archivio, oppure una promise senza callback.

Serializza `value` con `JSON.stringify()` e lo salva come `{id}.json`.

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

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

Type: `method`

Legge un file come stream.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'ID del file. |
| `callback` | `Function` | no |  | `function(err, meta)`. |
| `nostream` | `Boolean` | no | `false` | Non aprire uno stream del contenuto. |

Returns: `FileStorage|Promise` L'archivio, oppure una promise con l'oggetto meta.

Restituisce l'oggetto meta con `meta.stream`, uno stream leggibile del contenuto. Con `nostream` impostato a `true` l'oggetto meta arriva senza lo stream. Errori: `File not found`, `Invalid file`, `File is expired` o un errore del file system. Senza callback il metodo restituisce una promise.

Example: Inoltrare in un 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`

Legge solo i metadati di un file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'ID del file. |
| `callback` | `Function` | no |  | `function(err, meta, filename, fd)`. |
| `keepfd` | `Boolean` | no | `false` | Tiene aperto il file descriptor `fd`; devi chiuderlo tu. |

Returns: `FileStorage|Promise` L'archivio, oppure una promise con l'oggetto meta.

Legge l'header del file. Le date arrivano come oggetti `Date`. La callback riceve anche il percorso del file sul disco. A differenza di `fs.read()`, non controlla la scadenza. Senza callback il metodo restituisce una promise.

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

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

Type: `method`

Legge il contenuto di un file in un Buffer.

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

Returns: `FileStorage|Promise` L'archivio, oppure una promise con il buffer.

Legge l'intero file in memoria. Usa `fs.read()` per i file grandi. Senza callback il metodo restituisce una promise. La promise restituisce solo il buffer.

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

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

Type: `method`

Legge il contenuto di un file come Base64.

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

Returns: `FileStorage|Promise` L'archivio, oppure una promise con la stringa.

Legge l'intero file e lo codifica come stringa Base64. Senza callback il metodo restituisce una promise. La promise restituisce solo la stringa.

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`

Legge un file JSON.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'ID del file. |
| `callback` | `Function` | yes |  | `function(err, value, meta)`. |

Returns: `FileStorage` L'archivio.

Legge un file salvato da `fs.savejson()` e lo analizza. La callback è obbligatoria.

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

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

Type: `method`

Legge un'immagine memorizzata come Image.

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

Returns: `FileStorage|Promise` L'archivio, oppure una promise con l'immagine.

Restituisce un oggetto `Image` che legge il contenuto del file, così puoi ridimensionarlo o convertirlo e salvare il risultato. L'elaborazione delle immagini richiede GraphicsMagick o ImageMagick. Senza callback il metodo restituisce una promise. La promise restituisce solo l'immagine.

Example: Miniatura
```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`

Invia un file a una risposta HTTP.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `res` | `Response` | yes |  | L'oggetto risposta. |
| `options` | `Object` | yes |  | Le opzioni, vedi sopra. |
| `checkmeta` | `Function` | no |  | `function(meta)`; restituisci `false` per rispondere con `404`. |

Returns: `undefined`

Il metodo dietro `controller.filefs()` e `controller.imagefs()`. `options`: `id` (il file), `download` (`true` per il nome memorizzato, una stringa, oppure `function(name, type)` che restituisce il nome), `headers`, `done` (una callback), `nocompress`, e per le immagini `image: true`, `make` (`function(image, res)`) e `cache` (predefinito `true`). Supporta le richieste `If-Modified-Since` (`304`) e `Range` (`206`). Un file mancante o scaduto, oppure `checkmeta(meta)` che restituisce `false`, produce `404`.

Example: In una route con req e 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`

Copia il contenuto di un file sul disco.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'ID del file. |
| `path` | `String` | yes |  | Un file di destinazione, o una cartella. |
| `callback` | `Function` | no |  | `function(err, meta)`. |

Returns: `FileStorage|Promise` L'archivio, oppure una promise con l'oggetto meta.

Scrive il contenuto del file (senza l'intestazione) in `path`. Un percorso con un punto viene usato come nome del file; qualsiasi altro percorso è una cartella e il file mantiene il nome con cui è stato salvato. La cartella deve esistere. I file scaduti danno l'errore `File is expired`. Senza callback il metodo restituisce una promise.

Example: Esportare in una cartella
```js
FILESTORAGE('documents').copy(id, PATH.temp(), function(err, meta) {
	console.log(PATH.temp(meta.name));
});
```

Example: Esportare in un file
```js
await FILESTORAGE('documents').copy(id, PATH.temp('invoice.pdf'));
```

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

Type: `method` · Since: `0.0.99`

Copia un file all'interno dell'archiviazione con un nuovo ID.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'ID del file. |
| `newid` | `String` | no | `UID()` | L'ID della copia. |
| `callback` | `Function` | no |  | `function(err, meta)`; `meta.id` è il nuovo ID. |

Returns: `FileStorage|Promise` L'archiviazione, o una promise con l'oggetto meta.

Crea una copia del file con gli stessi metadati sotto `newid` e la aggiunge a `files.log`. Quando il secondo argomento è la callback, viene generato un nuovo ID con `UID()`. I file scaduti danno l'errore `File is expired`. Senza callback il metodo restituisce una promise. Nella forma con promise passa `newid`.

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

Example: Clonare con una promise
```js
var meta = await FILESTORAGE('documents').clone(id, UID());
```

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

Type: `method`

Cambia l'ID di un file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'ID del file. |
| `newid` | `String` | yes |  | Il nuovo ID. |
| `callback` | `Function` | no |  | `function(err)`. |

Returns: `FileStorage|Promise` L'archivio, oppure una promise.

Sposta il file nel nome e nella cartella di `newid`. `files.log` non viene modificato; chiama `fs.rebuild()` quando elenchi i file con `fs.browse()`. Senza callback il metodo restituisce una promise.

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

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

Type: `method`

Cambia il nome memorizzato di un file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'ID del file. |
| `newname` | `String` | yes |  | Il nuovo nome del file (al massimo 250 caratteri). |
| `callback` | `Function` | no |  | `function(err, meta)`. |

Returns: `FileStorage|Promise` L'archivio, oppure una promise con l'oggetto meta.

Scrive il nuovo nome nell'header e in `files.log`. Il content type resta lo stesso. Senza callback il metodo restituisce una promise.

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

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

Type: `method`

Rimuove un file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'ID del file. |
| `callback` | `Function` | no |  | `function(err)`. |

Returns: `FileStorage|Promise` L'archivio, oppure una promise.

Elimina il file dal disco e da `files.log`. Senza callback il metodo restituisce una promise.

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

### fs.browse([callback])

Type: `method`

Elenca i file da files.log.

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

Returns: `QueryBuilder` Il query builder.

Restituisce un query builder NoSQL su `files.log`, il database con i metadati di tutti i file. Aggiungi condizioni, ordinamento e paginazione, poi `callback()`.

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

### fs.browse2([callback])

Type: `method`

Elenca i file dal disco.

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

Returns: `FileStorage|Promise` L'archivio, oppure una promise con l'array.

Legge l'header di ogni file sul disco e restituisce i loro oggetti meta. Più lento di `fs.browse()`, ma non dipende da `files.log`. Senza callback il metodo restituisce una promise.

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

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

Type: `method`

Scorre tutti i file sul disco uno per uno.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `onfile` | `Function` | yes |  | `function(meta, next)`. |
| `callback` | `Function` | no |  | Viene eseguita quando tutti i file sono stati elaborati. |
| `workers` | `Number` | no |  | Quanti file vengono elaborati contemporaneamente. |

Returns: `FileStorage` L'archivio.

Chiama `onfile(meta, next)` per ogni file; chiama `next()` per continuare. `meta.index` è la posizione del file. `callback` viene eseguita alla fine.

Example: Trovare i file grandi
```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`

Conta i file e la loro dimensione da files.log.

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

Returns: `FileStorage` L'archivio.

Restituisce un oggetto con `count` (il numero di file) e `size` (la dimensione totale in byte), e aggiorna `fs.total` e `fs.size`.

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

### fs.count2([callback])

Type: `method`

Conta i file sul disco.

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

Returns: `FileStorage|Promise` L'archivio, oppure una promise con il numero.

Conta i file nelle sottocartelle dell'archivio, senza `files.log`. Senza callback il metodo restituisce una promise.

Example: Contare sul disco
```js
var count = await FILESTORAGE('photos').count2();
```

### fs.rebuild([callback])

Type: `method`

Ricrea files.log a partire dai file sul disco.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | Viene eseguita quando il log è stato scritto. |

Returns: `FileStorage|Promise` L'archivio, oppure una promise.

Legge tutti i file con `fs.browse2()`, scrive un nuovo `files.log` e imposta `fs.total` e `fs.size`. Usalo dopo `fs.move()` o quando `files.log` è andato perso. Senza callback il metodo restituisce una promise.

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

### fs.clean([callback])

Type: `method`

Rimuove i file scaduti.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | `function(err, count)`; `count` è il numero di file rimossi. |

Returns: `FileStorage|Promise` L'archivio, oppure una promise con il numero.

Trova in `files.log` i file la cui data `expire` è passata e li elimina. Senza callback il metodo restituisce una promise.

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

### fs.clear([callback])

Type: `method`

Rimuove tutti i file.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `callback` | `Function` | no |  | `function(err, count)`; `count` è il numero di file rimossi. |

Returns: `FileStorage|Promise` L'archivio, oppure una promise con il numero.

Elimina tutti i file, le loro sottocartelle e `files.log`. Durante l'esecuzione, le altre letture e i salvataggi restano in attesa. Senza callback il metodo restituisce una promise. Alias: `fs.drop()`.

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

### fs.drop([callback])

Type: `method`

Alias di fs.clear().

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

Returns: `FileStorage|Promise` L'archivio, oppure una promise con il numero.

Lo stesso metodo di `fs.clear()`.

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

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

Type: `method`

Scrive tutti i file in un unico file di backup.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `filename` | `String|Stream` | yes |  | Il file di destinazione o uno stream scrivibile. |
| `callback` | `Function` | no |  | `function(err, response)`; `response` ha `filename`, `files` e `size`. |

Returns: `FileStorage|Promise` L'archivio, oppure una promise con la risposta.

Ogni file viene compresso con GZIP e scritto in Base64. `filename` è un percorso o uno stream scrivibile. Senza callback il metodo restituisce una 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`

Ripristina l'archivio da un file di backup.

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

Returns: `FileStorage|Promise` L'archivio, oppure una promise.

Prima rimuove tutti i file attuali (come `fs.clear()`), poi estrae il backup creato da `fs.backup()`. Letture e salvataggi restano in attesa finché non termina. Senza callback il metodo restituisce una promise.

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

### fs.storage(directory)

Type: `method`

Cambia la cartella dell'archivio.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `directory` | `String` | yes |  | Il percorso assoluto della cartella. |

Returns: `FileStorage` L'archivio.

Imposta `fs.directory` e il percorso di `files.log` su un'altra cartella.

Example: Un altro disco
```js
FILESTORAGE('archive').storage('/mnt/archive/files/');
```

### fs.readfilename(id)

Type: `method`

Restituisce il percorso di un file sul disco.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `id` | `String` | yes |  | L'ID del file. |

Returns: `String` Il percorso assoluto.

Restituisce il percorso del `.file` per `id`. Il file inizia con un header di 2000 byte, quindi non è una copia del file originale; per quello usa `fs.copy()`.

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

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

Type: `method`

Risponde con un file da un archivio.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'archivio. |
| `id` | `String` | yes |  | L'ID del file. |
| `download` | `Boolean|String|Function` | no |  | `true`, un nome di file, oppure `function(name, type)` che restituisce il nome. |
| `headers` | `Object` | no |  | Header di risposta aggiuntivi. |
| `callback` | `Function` | no |  | Viene eseguita quando il file è stato inviato. |
| `checkmeta` | `Function` | no |  | `function(meta)`; restituisci `false` per rispondere con `404`. |

Returns: `Controller` Il controller.

Invia il file `id` di `FILESTORAGE(name)` con il suo content type memorizzato. `download` impostato a `true` usa il nome memorizzato, una stringa imposta un altro nome. `checkmeta(meta)` che restituisce `false` produce `404`. Sono supportate le richieste `Range` e `If-Modified-Since`. L'oggetto risposta ha lo stesso metodo, `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`

Risponde con un'immagine elaborata da un archivio.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `name` | `String` | yes |  | Il nome dell'archivio. |
| `id` | `String` | yes |  | L'ID del file. |
| `make` | `Function` | yes |  | `function(image, res)` che modifica l'immagine. |
| `headers` | `Object` | no |  | Header di risposta aggiuntivi. |
| `callback` | `Function` | no |  | Viene eseguita quando l'immagine è stata inviata. |
| `checkmeta` | `Function` | no |  | `function(meta)`; restituisci `false` per rispondere con `404`. |

Returns: `Controller` Il controller.

Legge l'immagine `id` di `FILESTORAGE(name)`, chiama `make(image, res)` per elaborarla e invia il risultato. L'immagine elaborata viene messa in cache nella cartella temporanea per ogni URL. Richiede GraphicsMagick o ImageMagick. L'oggetto risposta ha lo stesso metodo, `res.imagefs()`.

Example: Miniatura
```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`

Salva un file caricato in un archivio.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `storage` | `String` | yes |  | Il nome dell'archivio. |
| `id` | `String` | yes |  | L'ID del file. |
| `custom` | `Object` | no |  | Qualsiasi dato conservato con il file. |
| `expire` | `String` | no |  | Un periodo di scadenza. |
| `callback` | `Function` | no |  | `function(err, meta)`. |

Returns: `FileStorage|Promise` L'archivio, oppure una promise con l'oggetto meta.

Un metodo di ogni file in `controller.files`. Chiama `FILESTORAGE(storage).save()` con il nome originale del file e il file temporaneo dell'upload. Senza callback restituisce una 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 });
}
```
