# Descargar media entrante

`GET /v1/media/:mediaId`

Un evento `message.received` trae un **id** de media, no los bytes. Bajarlos requiere el token de la conexión, que tenemos nosotros → pedílos en GET /v1/media/:mediaId. Hacemos stream directo (nunca lo guardamos). Un media id que no es de tu cuenta → 404 (nunca confirmamos media ajena).

## Ejemplos

### cURL

```bash
# The media id comes from a message.received event: data.message.image.id (etc.)
curl https://api.waiaconnect.com/v1/media/1234567890 \
  -H "Authorization: Bearer wc_live_YOUR_API_KEY" \
  -o downloaded-media.bin   # Content-Type comes back on the response
```

### Node.js

```javascript
import { writeFile } from "fs/promises";
// The media id comes from a message.received event: data.message.image.id (etc.)
const res = await fetch("https://api.waiaconnect.com/v1/media/1234567890", {
  headers: { "Authorization": "Bearer wc_live_YOUR_API_KEY" }
});
if (res.status === 404) throw new Error("Not your media id");
const buf = Buffer.from(await res.arrayBuffer());
await writeFile("downloaded-media.bin", buf); // res.headers.get("content-type") = the MIME
```

### PHP

```php
<?php
// The media id comes from a message.received event: data["message"]["image"]["id"] (etc.)
$ch = curl_init("https://api.waiaconnect.com/v1/media/1234567890");
curl_setopt_array($ch, [
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => ["Authorization: Bearer wc_live_YOUR_API_KEY"],
]);
$bytes = curl_exec($ch);
if (curl_getinfo($ch, CURLINFO_HTTP_CODE) === 404) { throw new Exception("Not your media id"); }
file_put_contents("downloaded-media.bin", $bytes);
```

### Python

```python
import requests
# The media id comes from a message.received event: data["message"]["image"]["id"] (etc.)
res = requests.get("https://api.waiaconnect.com/v1/media/1234567890",
  headers={"Authorization": "Bearer wc_live_YOUR_API_KEY"}, stream=True)
if res.status_code == 404:
    raise Exception("Not your media id")
with open("downloaded-media.bin", "wb") as f:
    for chunk in res.iter_content(8192):
        f.write(chunk)  # res.headers["content-type"] = the MIME
```

## Notas

- El `mediaId` sale del evento: `data.message.image.id` (o `.document.id`, `.audio.id`, `.video.id`).
- ⚠ Un identificador que llega por webhook **vence a los 7 días**: después Meta ya no lo resuelve y te devolvemos 404. Si necesitás el archivo más tiempo, bajalo y guardalo vos.
- Éste es además **el único tipo de identificador que existe en Connect** — no hay subida. Para MANDAR un archivo tuyo, ver «Enviar media».
