# Uploads und Dokumente

> Signierte PUT-Adresse, Prüfung, Typen und Grenzen.

Quelle: https://flow-marketing.org/hilfe/api-uploads-und-dokumente · Frage: Wie lade ich Bilder, Logos und Dokumente für die API hoch?

Dateien gehen nie im JSON-Körper mit. Du legst einen Upload an, lädst die Datei per PUT an eine signierte Adresse und schließt ab. Erst dann prüft Flow Marketing Dateikopf und Viren und gibt die Datei frei.

Bilder und Logos nutzt du danach als upl_… in der Marke und in Stilfilm-Feldern. PowerPoint, PDF und Word laufen über /documents und werden zum Video.

## Ablauf in drei Schritten {#ablauf}

Die signierte Adresse zeigt in eine Quarantäne auf unserem Speicher. Keine Datei wird verwendet, bevor `/complete` sie geprüft hat. Nicht abgeschlossene Uploads löschen wir samt Datei nach 24 Stunden.

1. `POST /uploads` (oder `POST /documents`) mit Dateiname und genauer Größe in Bytes. Die Antwort enthält `upload_url`, `upload_method` (`PUT`), `upload_headers` und `upload_expires_in_s` (900 = 15 Minuten).
2. Die Datei per PUT an `upload_url` senden, mit genau den Kopfzeilen aus `upload_headers`. Bei `/uploads` sind Typ und Größe mitsigniert: Die Datei muss genau `size_bytes` groß sein.
3. `POST /uploads/{id}/complete` (bzw. `/documents/{id}/complete`). Jetzt wird geprüft. Bei Erfolg ist `status` gleich `ready`.

**curl**

```bash
# 1. create (size_bytes = exact file size)
curl -X POST https://flow-marketing.org/api/turbo/v1/uploads \
  -H "Authorization: Bearer $FLOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"kind\": \"logo\", \"filename\": \"logo.png\", \"size_bytes\": $(wc -c < logo.png)}"

# 2. upload the file to upload_url within 15 minutes (headers from upload_headers)
curl -X PUT "$UPLOAD_URL" -H "Content-Type: image/png" --data-binary @logo.png

# 3. complete: header check, virus scan, image check
curl -X POST https://flow-marketing.org/api/turbo/v1/uploads/upl_4dF6gH8jK0lZ2xC4vB6n/complete \
  -H "Authorization: Bearer $FLOW_API_KEY"
```

**JavaScript**

```js
import { readFile } from 'node:fs/promises'

const BASE = 'https://flow-marketing.org/api/turbo/v1'
const H = { Authorization: 'Bearer ' + process.env.FLOW_API_KEY, 'Content-Type': 'application/json' }
const file = await readFile('logo.png')

// 1. create
const up = await (await fetch(BASE + '/uploads', {
  method: 'POST',
  headers: H,
  body: JSON.stringify({ kind: 'logo', filename: 'logo.png', size_bytes: file.length }),
})).json()

// 2. PUT to the signed URL (15 minutes)
const put = await fetch(up.upload_url, { method: up.upload_method, headers: up.upload_headers, body: file })
if (!put.ok) throw new Error('upload failed: ' + put.status)

// 3. complete
const done = await (await fetch(BASE + '/uploads/' + up.id + '/complete', { method: 'POST', headers: H })).json()
console.log(done.id, done.status) // 'ready' → use done.id as brand.logo
```

**Python**

```python
import os, requests

BASE = "https://flow-marketing.org/api/turbo/v1"
H = {"Authorization": "Bearer " + os.environ["FLOW_API_KEY"]}
data = open("logo.png", "rb").read()

# 1. create
up = requests.post(BASE + "/uploads", headers=H, json={"kind": "logo", "filename": "logo.png", "size_bytes": len(data)}, timeout=30).json()

# 2. PUT to the signed URL (15 minutes)
put = requests.put(up["upload_url"], data=data, headers=up["upload_headers"], timeout=120)
put.raise_for_status()

# 3. complete
done = requests.post(BASE + "/uploads/" + up["id"] + "/complete", headers=H, timeout=120).json()
print(done["id"], done["status"])  # "ready" → use done["id"] as brand.logo
```

## Upload anlegen: POST /uploads {#upload-anlegen}

Antwort 201: das Upload-Objekt plus `upload_url`, `upload_method`, `upload_headers`, `upload_expires_in_s` und `max_bytes`. Unbekannte Felder ergeben 422. Recht: `videos:write`.

| Feld | Bedeutung |
| --- | --- |
| `kind` | Pflicht: `image`, `logo` oder `document` |
| `filename` | Pflicht, mit Endung; bis 160 Zeichen |
| `size_bytes` | Pflicht: genaue Größe, ab 100 Bytes bis zur Grenze der Art |
| `content_type` | optional; der Typ ergibt sich aus der Endung |

**Antwort 201**

```json
{
  "id": "upl_4dF6gH8jK0lZ2xC4vB6n",
  "object": "upload",
  "kind": "logo",
  "status": "awaiting_upload",
  "filename": "logo.png",
  "content_type": "image/png",
  "size_bytes": 48213,
  "width": null,
  "height": null,
  "sha256": null,
  "error": null,
  "created_at": "2026-11-22T09:00:00.000Z",
  "ready_at": null,
  "upload_url": "https://...",
  "upload_method": "PUT",
  "upload_headers": { "content-type": "image/png" },
  "upload_expires_in_s": 900,
  "max_bytes": 15728640
}
```

## Typen und Grenzen {#grenzen}

Uploads: höchstens 200 je Tag (UTC) und Konto – Löschen gibt keine frei (429 `daily_upload_limit`). Je Konto laufen höchstens 3 Prüfungen gleichzeitig (429 `upload_concurrency`).

SVG nehmen wir nicht an, weil es Skripte enthalten kann. Speichere Logos als PNG mit Transparenz oder als WebP.

| Art | Endungen | Größe | Weitere Grenzen |
| --- | --- | --- | --- |
| `image`, `logo` | `.png`, `.jpg`, `.jpeg`, `.webp` (kein SVG) | bis 15 MB (15.728.640 Bytes) | höchstens 50 Megapixel |
| `document` (Upload) | `.pptx`, `.pdf`, `.docx` | bis 50 MB (52.428.800 Bytes) | – |
| `/documents` | `.pptx`, `.pdf`, `.docx` | bis 50 MB | höchstens 30 Dokumente je 24 Stunden und Konto |

## Was beim Abschließen geprüft wird {#pruefung}

`/complete` darfst du wiederholen: Ist der Upload schon `ready`, kommt er unverändert zurück. Status-Werte: `awaiting_upload`, `checking`, `ready`, `rejected`, `failed`. Bei Ablehnung steht der Grund in `error.code`.

- Die Datei ist da und hat die angemeldete Größe.
- Der Dateikopf passt zur Endung (PNG, JPEG, WebP; PDF beginnt mit `%PDF-`, PowerPoint und Word sind ZIP-Dateien).
- Bilder: höchstens 50 Megapixel – schon im Dateikopf geprüft.
- Virenscan. Bei einem Fund wird die Datei gelöscht.
- Bilder werden neu gespeichert: Drehung aus den Kamera-Daten übernommen, Metadaten entfernt.
- Bildschutz: Nacktheit und intime Darstellungen werden nie gespeichert.

## Fehler beim Hochladen {#fehler}

| Status | Code | Bedeutung |
| --- | --- | --- |
| 422 | `validation_failed` | Feld fehlt oder ist unbekannt |
| 422 | `upload_type` | Endung nicht erlaubt, oder der Inhalt passt nicht zur Endung |
| 422 / 413 | `upload_size` | `size_bytes` außerhalb der Grenze, Datei leer oder zu groß |
| 409 | `upload_missing` | die Datei ist noch nicht hochgeladen |
| 409 | `upload_busy` | wird gerade geprüft (`Retry-After: 5`) |
| 409 | `upload_state` | lässt sich nicht mehr abschließen (zum Beispiel abgelehnt) |
| 422 | `upload_image_too_large` | mehr als 50 Megapixel |
| 422 | `upload_image_invalid` | Bild nicht lesbar |
| 422 | `upload_virus` | Virenfund, Datei gelöscht |
| 422 | `image_not_allowed` | vom Bildschutz abgelehnt |
| 503 | `upload_scan_unavailable` | Virenprüfung gerade nicht möglich; die Datei bleibt in der Quarantäne – in einer Minute erneut abschließen |
| 503 | `upload_image_check_unavailable`, `image_check_unavailable` | Bildprüfung gerade nicht möglich; wie oben |
| 429 | `upload_concurrency` | mehr als 3 Prüfungen gleichzeitig |
| 429 | `daily_upload_limit` | 200 Uploads für heute erreicht |

## Uploads verwenden {#verwenden}

Uploads der Art `document` nutzt heute noch kein Video-Feld. Für Videos aus PowerPoint, PDF oder Word nimm `/documents`.

- `brand.logo` und `brand.logo_dark` in `POST /videos` und `PATCH /videos/{id}`: Uploads der Art `logo` oder `image`.
- Logo- und Bildfelder von Stilfilm-Vorlagen: Logo-Felder nehmen `logo` oder `image`, Bildfelder nur `image`.
- Nur fertige Uploads (`ready`) desselben Kontos und Modus. Ein Testschlüssel kann keine Live-Uploads nutzen.

## Uploads lesen und löschen {#uploads-verwalten}

`GET /uploads` liefert die letzten 100 Uploads des Modus, ohne Seiten. `GET /uploads/{id}` zeigt den Stand – nie den Inhalt oder Speicher-Pfade. `DELETE /uploads/{id}` löscht Datei und Eintrag; Antwort `{"id", "object": "upload", "deleted": true}`.

Das Upload-Objekt: `id`, `kind`, `status`, `filename`, `content_type`, `size_bytes`, `width`, `height`, `sha256` (nach der Prüfung), `error`, `created_at`, `ready_at`.

## Dokumente: POST /documents {#dokumente}

Für Videos aus PowerPoint (.pptx), PDF und Word (.docx). Google Slides exportierst du vorher als .pptx oder PDF. Körper: `filename` (mit Endung), `size_bytes` (ganze Zahl, höchstens 50 MB), optional `content_type`. Antwort 201 mit dem Dokument-Objekt und Upload-Angaben wie bei `/uploads` (PUT, 15 Minuten).

Nach dem PUT liest `POST /documents/{id}/complete` die Datei: Dateikopf, Virenscan, dann Folien bzw. Seiten. Gelesen wird auf unserem Server; die Datei geht an keinen fremden Dienst. Lesen kostet nichts. Danach baust du mit `POST /videos/from-document` das Video.

Fehler der Dokument-Prüfung haben Codes, die mit `document_` beginnen; `detail` sagt, was nicht passt.

**curl**

```bash
# 1. create
curl -X POST https://flow-marketing.org/api/turbo/v1/documents \
  -H "Authorization: Bearer $FLOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{\"filename\": \"pitch.pptx\", \"size_bytes\": $(wc -c < pitch.pptx)}"

# 2. PUT the file (headers from upload_headers)
curl -X PUT "$UPLOAD_URL" \
  -H "Content-Type: application/vnd.openxmlformats-officedocument.presentationml.presentation" \
  --data-binary @pitch.pptx

# 3. complete: type check, virus scan, read slides
curl -X POST https://flow-marketing.org/api/turbo/v1/documents/dok_8sD0fG2hJ4kL6zX8cV0b/complete \
  -H "Authorization: Bearer $FLOW_API_KEY"
```

**JavaScript**

```js
import { readFile } from 'node:fs/promises'

const BASE = 'https://flow-marketing.org/api/turbo/v1'
const H = { Authorization: 'Bearer ' + process.env.FLOW_API_KEY, 'Content-Type': 'application/json' }
const file = await readFile('pitch.pptx')

const doc = await (await fetch(BASE + '/documents', {
  method: 'POST',
  headers: H,
  body: JSON.stringify({ filename: 'pitch.pptx', size_bytes: file.length }),
})).json()
await fetch(doc.upload_url, { method: doc.upload_method, headers: doc.upload_headers, body: file })
const read = await (await fetch(BASE + '/documents/' + doc.id + '/complete', { method: 'POST', headers: H })).json()
console.log(read.status, read.title, read.pages_total, read.warnings)
```

**Python**

```python
import os, requests

BASE = "https://flow-marketing.org/api/turbo/v1"
H = {"Authorization": "Bearer " + os.environ["FLOW_API_KEY"]}
data = open("pitch.pptx", "rb").read()

doc = requests.post(BASE + "/documents", headers=H, json={"filename": "pitch.pptx", "size_bytes": len(data)}, timeout=30).json()
requests.put(doc["upload_url"], data=data, headers=doc["upload_headers"], timeout=300).raise_for_status()
read = requests.post(BASE + "/documents/" + doc["id"] + "/complete", headers=H, timeout=300).json()
print(read["status"], read["title"], read["pages_total"], read["warnings"])
```

**Antwort auf complete (gekürzt)**

```json
{
  "id": "dok_8sD0fG2hJ4kL6zX8cV0b",
  "object": "document",
  "status": "ready",
  "kind": "pptx",
  "filename": "pitch.pptx",
  "size_bytes": 2483910,
  "error_code": null,
  "title": "Musterwerk 2027",
  "language": "de",
  "pages_total": 12,
  "pages": [
    { "number": 1, "title": "Musterwerk 2027", "hidden": false, "bullets": 0, "has_notes": true, "numbers": [], "chart": null, "table": false, "images": 1 },
    { "number": 2, "title": "Umsatz", "hidden": false, "bullets": 3, "has_notes": true, "numbers": [{ "value": 42, "unit": "%" }], "chart": { "title": "Umsatz je Quartal", "points": 4 }, "table": false, "images": 0 }
  ],
  "images": 5,
  "warnings": [],
  "video_id": null,
  "created_at": "2026-11-22T09:00:00.000Z",
  "delete_after": "2026-11-29T09:00:00.000Z"
}
```

## Das Dokument-Objekt {#dokument-objekt}

`GET /documents/{id}` zeigt den Stand und was gelesen wurde – nur den Aufbau, nie den vollen Inhalt. `DELETE /documents/{id}` löscht das Dokument samt Bildern; Antwort `{"id", "object": "document", "deleted": true}`. Eine Liste aller Dokumente gibt es nicht.

| Feld | Bedeutung |
| --- | --- |
| `id` | `dok_` plus 20 Zeichen |
| `status` | `awaiting_upload`, `processing`, `ready`, `rejected`, `failed`, `deleted` |
| `kind` | `pptx`, `pdf` oder `docx` |
| `filename`, `size_bytes` | wie angemeldet |
| `error_code` | Grund bei Ablehnung, sonst `null` |
| `title`, `language` | gelesener Titel und Sprache (`de` oder `en`) |
| `pages_total` | Zahl der Folien oder Seiten |
| `pages` | je Seite: `number`, `title`, `hidden`, `bullets` (Anzahl Punkte), `has_notes`, `numbers` (`value`, `unit`), `chart` (`title`, `points`), `table`, `images` |
| `images` | Zahl der Bilder |
| `warnings` | Hinweise mit `code`, `de`, `en` |
| `video_id` | das zuletzt daraus gebaute Video |
| `created_at`, `delete_after` | angelegt; wann wir Dokument und Bilder löschen |

## Weiter

- [Videos (brand, from-document)](https://flow-marketing.org/hilfe/api-videos)
- [Vorlagen (Stilfilm-Felder)](https://flow-marketing.org/hilfe/api-vorlagen)
- [Datei geht nicht hoch](https://flow-marketing.org/hilfe/datei-geht-nicht-hoch)
