# Gestione dei file

## Carica file

> **POST** `/v3/files`

Carica un file sulla piattaforma Tripo e ottieni uno file_token per le successive chiamate API.

### Richiedi parametri

#### Richiedi intestazioni

| Parametro | Digitare | Obbligatorio | Predefinito | Descrizione |
| :-: | :-: | :-: | :-: | :-: |
| Content-Type | stringa | Sì | — | `multipart/form-data` |
| Authorization | stringa | Sì | — | `Bearer {api_key}` |

#### Richiedi corpo (multipart/form-data)

| Parametro | Digitare | Obbligatorio | Predefinito | Descrizione |
| :-: | :-: | :-: | :-: | :-: |
| file | binario | Sì | — | Dati dell'archivio. Le immagini supportano JPEG/PNG, fino a 20 MB. I modelli supportano GLB/GLTF/FBX/OBJ/STL, fino a 150 MB |

#### Richiedi esempio

##### curl

```bash
curl -X POST https://openapi.tripo3d.ai/v3/files \
  -H "Authorization: Bearer {api_key}" \
  -F "file=@/path/to/model.glb"
```

##### Python

```python
import requests

url = "https://openapi.tripo3d.ai/v3/files"
headers = {
    "Authorization": "Bearer {api_key}"
}
files = {
    "file": open("/path/to/model.glb", "rb")
}

response = requests.post(url, headers=headers, files=files)
print(response.json())
```

##### JavaScript

```javascript
const url = "https://openapi.tripo3d.ai/v3/files";

const formData = new FormData();
formData.append("file", fileBlob, "model.glb");

const response = await fetch(url, {
  method: "POST",
  headers: {
    "Authorization": "Bearer {api_key}"
  },
  body: formData
});

const data = await response.json();
console.log(data);
```

### Risposta

#### Risposta riuscita

```json
{
  "code": 0,
  "data": {
    "file_token": "file_abc123"
  }
}
```

#### Campi di risposta

| Parametro | Digitare | Descrizione |
| :-: | :-: | :-: |
| code | intero | Codice di stato. `0` indica successo |
| data.file_token | stringa | Identificatore di file univoco utilizzato per le successive chiamate API |

---

## Ottieni le credenziali di caricamento

> **POST** `/v3/files/upload-credentials`

Ottieni le credenziali di caricamento diretto (STS) per caricare file di grandi dimensioni direttamente dal client all'archivio cloud.

### Richiedi parametri

#### Richiedi intestazioni

| Parametro | Digitare | Obbligatorio | Predefinito | Descrizione |
| :-: | :-: | :-: | :-: | :-: |
| Content-Type | stringa | Sì | — | `application/json` |
| Authorization | stringa | Sì | — | `Bearer {api_key}` |

#### Richiedi esempio

##### curl

```bash
curl -X POST https://openapi.tripo3d.ai/v3/files/upload-credentials \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer {api_key}"
```

##### Python

```python
import requests

url = "https://openapi.tripo3d.ai/v3/files/upload-credentials"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer {api_key}"
}

response = requests.post(url, headers=headers)
print(response.json())
```

##### JavaScript

```javascript
const url = "https://openapi.tripo3d.ai/v3/files/upload-credentials";

const response = await fetch(url, {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer {api_key}"
  }
});

const data = await response.json();
console.log(data);
```

### Risposta

#### Risposta riuscita

```json
{
  "code": 0,
  "data": {
    "file_token": "file_abc123",
    "upload_url": "https://storage.example.com/upload/...",
    "expires_at": "2025-01-01T01:00:00Z"
  }
}
```

#### Campi di risposta

| Parametro | Digitare | Descrizione |
| :-: | :-: | :-: |
| code | intero | Codice di stato. `0` indica successo |
| data.file_token | stringa | Identificatore di file univoco |
| data.upload_url | stringa | Caricamento prefirmato URL. Il client carica il file direttamente con PUT |
| data.expires_at | stringa | Scadenza credenziali (ISO 8601) |
