---
title: Caricare file
project: OpenFiles
version: 1.0
section: reference
language: it
license: MIT
url: https://totaljs.es/docs/it/openfiles/1-0/reference/upload/
updated: 2026-11-19T07:45:44.888Z
---

# Caricare file

> POST /upload/{db}/: carica uno o più file come multipart/form-data.

```text
POST /upload/{db}/
POST /files/{db}/
```

Entrambi i percorsi fanno la stessa cosa. Invia i file come `multipart/form-data`, con il [token](../rest-api/) nell'argomento di query `token` o nell'header `x-token`. Il token ha bisogno di **Upload files** e dello storage `{db}`. Una richiesta può arrivare a 100 MB.

## Argomenti di query

| Argomento | Significato |
|---|---|
| `token` | Il token API, se non usi l'header `x-token`. |
| `hostname=1` | Restituisce un `url` assoluto con l'indirizzo di OpenFiles. |
| `id` | Un tuo ID per il file caricato. Usa solo lettere e cifre. |

## Un file

```bash
curl -H "x-token: YOUR_TOKEN" -F file=@sunset.png "https://files.example.com/upload/photos/"
```

La risposta è un oggetto:

```json
{"id":"JapO3b1e961f","name":"sunset.png","size":2795,"type":"image/png","width":640,"height":480,"ext":"png","url":"/files/photos/JapO3b1e961f-pn.png"}
```

## Più file

Invia più campi file in una sola richiesta:

```bash
curl -H "x-token: YOUR_TOKEN" -F file1=@sea.png -F file2=@forest.png "https://files.example.com/upload/photos/"
```

La risposta è un array, con un oggetto per ogni file:

```json
[{"id":"JapO3b1f960f","name":"sea.png","size":3577,"type":"image/png","width":800,"height":600,"ext":"png","url":"/files/photos/JapO3b1f960f-pn.png"},{"id":"JapO3b1g961f","name":"forest.png","size":1591,"type":"image/png","width":400,"height":300,"ext":"png","url":"/files/photos/JapO3b1g961f-pp.png"}]
```

## Link assoluto e un tuo ID

```bash
curl -H "x-token: YOUR_TOKEN" -F file=@sea.png "https://files.example.com/upload/photos/?id=homepagebanner&hostname=1"
```

```json
{"id":"homepagebanner","name":"sea.png","size":3577,"type":"image/png","width":800,"height":600,"ext":"png","url":"https://files.example.com/files/photos/homepagebanner-14s.png"}
```

Puoi anche impostare l'ID per ogni file con un campo del modulo chiamato come il campo file più `_id`. Qui il campo file è `file`, quindi il campo dell'ID è `file_id`:

```bash
curl -H "x-token: YOUR_TOKEN" -F file=@forest.png -F file_id=forestthumb "https://files.example.com/upload/photos/"
```

```json
{"id":"forestthumb","name":"forest.png","size":1591,"type":"image/png","width":400,"height":300,"ext":"png","url":"/files/photos/forestthumb-xf.png"}
```

Quando carichi di nuovo con un ID che esiste già, il link serve il nuovo file. Leggi [Sostituire un file allo stesso link](../../recipes/replace-file/).

## Qualsiasi tipo di file

Viene accettato qualsiasi tipo di file. Per i file che non sono immagini, `width` e `height` valgono `0`:

```json
{"id":"JapO3b1h960f","name":"price-list.txt","size":38,"type":"text/plain","width":0,"height":0,"ext":"txt","url":"/files/photos/JapO3b1h960f-pp.txt"}
```

Leggi [Errori e limiti](../errors/) per i casi di errore.
