# upload

Canonical URL: https://developers.iagenify.com/pt/sdk/ref/connected-storage/run-write/upload/
Language: pt

`storage.run({ action: "upload", key, content | contentBase64, contentType })`

Metìs bytes sotto una chiave. Texto tal qualquondo, ninguna altra cosa como base64 — e que la distinzion non è optativa.

Status: object storage · free · replaces without warning

## Parâmetros {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `key` | string | obrigatório | Le slashes sono caracteres, non cartelle. |
| `content` | string |  | Contenuto di testo, inviato come è. |
| `contentBase64` | string |  | **Qualquer cosa binaria.** Base64 dei bytes. |
| `contentType` | string |  | Quale è. Vale la pena impostare — decide come un lector lo tratta. |

```javascript
// Text
await storage.run({ action: "upload", key: "notes/today.md",
  content: "# Today\n\n…", contentType: "text/markdown" });

// Binary — base64, always
await storage.run({ action: "upload", key: "invoices/2026/01/a.pdf",
  contentBase64: pdfBuffer.toString("base64"), contentType: "application/pdf" });
// { ok: true, key: "invoices/2026/01/a.pdf", size: 183204 }
```

> **Binario inviat come text arriva corros**
>
> Un buffer secratificat passa attraverso una codificatura di testo che non sopravà a octets arbitrari. Il upload succede e il file è rotto — che è la pire specie de fallimento, perché nulla lo informa.

## Se substitue sine chiedere {#replace}

Una chiave existente è sovrascrit e la risposta è igual a una scrittura fresca. Non vi è una versione anterior.

```javascript
// Check first, if replacing would be wrong
const page = await storage.run({ action: "list", prefix: key });
if ((page.objects || []).some((o) => o.key === key)) {
  throw new Error(`${key} already exists`);
}

await storage.run({ action: "upload", key, contentBase64, contentType });
```

## Disegna la chiave prima di scriver {#keys}

- Prefixi di slashes e prefixi sono i soli raggrupament di un storage d'objets ha.
- Metîe quello che filtrare da a sinistra: `invoices/2026/01/` listes un mese; `01/2026/invoices/` non lo fa.
- Le teclas sono difficult a cambiare più tard — renominare è una copia e un elimina, un objeto a la volta.

## Refuse quando lo spazio è pieno {#quota}

`quota_exceeded`, verificat prima che i bytes siano inviati. [usage](/pt/sdk/ref/connected-storage/run/usage), prima che un'importazione grande sia più barata di trovare la mitjana.

- [objete](/pt/sdk/ref/connected-storage/run/object): Relire ce qu'on a dépôt.
- [lista](/pt/sdk/ref/connected-storage/run/list): Les clés, et leurs talles.
- [run()](/pt/sdk/ref/connected-storage/run): Tutes les actions, les garde-fous et ce que chaque coute.

```python
import base64

# Text
storage.run(action="upload", key="notes/today.md",
            content="# Today\n\n…", contentType="text/markdown")

# Binary — base64, always
storage.run(action="upload", key="invoices/2026/01/a.pdf",
            contentBase64=base64.b64encode(pdf_bytes).decode(), contentType="application/pdf")
# {"ok": True, "key": "invoices/2026/01/a.pdf", "size": 183204}
```

```python
# Check first, if replacing would be wrong
page = storage.run(action="list", prefix=key)
if any(o["key"] == key for o in page.get("objects") or []):
    raise FileExistsError(f"{key} already exists")

storage.run(action="upload", key=key, contentBase64=content_base64, contentType=content_type)
```
