# upload

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

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

Puts bytes under a key. Text as it is, anything else as base64 — and that distinction is not optional.

Status: object storage · free · replaces without warning

## Parameters {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `key` | string | required | Where it goes. Slashes are characters, not folders. |
| `content` | string |  | Text content, sent as it is. |
| `contentBase64` | string |  | **Anything binary.** Base64 of the bytes. |
| `contentType` | string |  | What it is. Worth setting — it decides how a reader treats it. |

```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 }
```

> **Binary sent as text arrives corrupted**
>
> A Buffer stringified goes through a text encoding that does not survive arbitrary bytes. The upload succeeds and the file is broken — which is the worst kind of failure, because nothing reports it.

## It replaces without asking {#replace}

An existing key is overwritten and the response looks the same as a fresh write. There is no previous version.

```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 });
```

## Design the key before the first write {#keys}

- Slashes make prefixes, and prefixes are the only grouping an object storage has.
- Put what you will filter by on the left: `invoices/2026/01/` lists a month; `01/2026/invoices/` does not.
- Keys are hard to change later — renaming is a copy and a delete, one object at a time.

## Refused when the space is full {#quota}

`quota_exceeded`, checked before the bytes are sent. [usage](/sdk/ref/connected-storage/run/usage) before a large import is cheaper than finding out halfway.

- [object](/sdk/ref/connected-storage/run/object): Relire ce qu'on a déposé.
- [list](/sdk/ref/connected-storage/run/list): Les clés, et leurs tailles.
- [run()](/sdk/ref/connected-storage/run): Toutes les actions, les garde-fous et ce que chacune coûte.

```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)
```
