# Visão geral

Canonical URL: https://developers.iagenify.com/pt/sdk/ref/files/
Language: pt

Fissari tenuti sul conto: creati localmente, salvati in un storage, letti, sostituiti, eliminati.

Status: 4 methods · 2 on the file · 1 credit to save · reading is free

La forma è inusual e vale una frase: `create()` non fa ningun lugar. Ti da un oggetto che riempie, e `save()` è lo che raggiunge il server. Quella separazion è lo que lascia il medesimo objete ser scrit al disco, al conto, o a ambos.

## La superficie {#methods}

| Chamada | Função | Custos |
| --- | --- | --- |
| api.files.create({ name, content, mimeType }) | Construe un objete de file. | niente |
| file.save({ storageId, path, localOnly }) | Lo scrie — al cont, al disco, o a ambos. | 1 credito |
| file.update() | Sostitue il conteniu di un ya salvat. | niente |
| api.files.get(sourceId) | Lee un retro, contenuto incluso. | niente |
| api.files.list() | Cada file del cont. | niente |
| api.files.delete(sourceId) | Lo remove, e lo che era indexat de lui. | niente |

## Fine a fin {#walk}

```javascript
// 1. Build it — nothing has happened yet
const file = api.files.create({
  name: "report.md",
  content: "# Q4\n\nRevenue was…",
  mimeType: "text/markdown",
});

// 2. Save it — this is the call that spends
const saved = await file.save();
saved.sourceId;      // how you will find it again
file.sourceId;       // the object learned its own id

// 3. Read it back, anywhere
const again = await api.files.get(saved.sourceId);
again.content;       // "# Q4\n\nRevenue was…"

// 4. Replace its content
again.content = "# Q4\n\nRevised.";
await again.update();

// 5. Remove it
await api.files.delete(saved.sourceId);
```

## Onde va un file {#where}

Al storage predefinito del cont, a meno che non si nomine un altro con `storageId`. Un tipo di storage non può tomî-lo.

> **Un computer o un telefono conserva i propri files**
>
> Salvare a un a través del server è negato con storage_is_local, prima di ogni credito è gasta — non un fallo, un'indicazione: quei bytes vivon su quel dispositivo. Legga e scrie-le dal dispositivo stesso.

Che significa `api.files` è para i files de la conta. Per i propri files de la machina, ved [LocalFiles](/pt/sdk/ref/local-files); para i contenuti de un storage de objetos, [storage.run()](/pt/sdk/ref/connected-storage/run).

## La categoria è dedut, non dichiara {#category}

| Tipomime | categoria |
| --- | --- |
| Imagem/* | Imagem |
| audio/* | audio |
| video/* | video |
| Json · yaml · xml · csv | Dati |
| ningun altro | document |

Importa per un motivo: un `document` è indexat per la ricerca semantica dopo che è salvat, quindi si può trovare per significat posteriore.

## Due cose vale la pena sapere prima di edificar su {#two}

- **Costuis de salvament un credit**, rimborsat integralmente se la scrittura non fa. Lectura, lista e cancellazione non costa nulla.
- **L'oggetto de file è un manico che tu riempis.** `create()` nunca tocca la rete, quindi una superficie de erros de validazione a `save()`.

- [file.save()](/pt/sdk/ref/files/save): L'invocazione che scrie, e le tre modalitae di usarlo.
- [get()](/pt/sdk/ref/files/get): Legtura di un dos, de texto o binar.
- [api.storage](/pt/sdk/ref/storage): I luoghi a cui un file puère ser salvat.

```python
# 1. Build it — nothing has happened yet
file = api.files.create(
    name="report.md",
    content="# Q4\n\nRevenue was…",
    mime_type="text/markdown",
)

# 2. Save it — this is the call that spends
saved = file.save()
saved["sourceId"]    # how you will find it again
file.source_id       # the object learned its own id

# 3. Read it back, anywhere
again = api.files.get(saved["sourceId"])
again.content        # "# Q4\n\nRevenue was…"

# 4. Replace its content
again.content = "# Q4\n\nRevised."
again.update()

# 5. Remove it
api.files.delete(saved["sourceId"])
```
