# `KapsoEx.WhatsApp.Media`
[🔗](https://github.com/rocket4ce/kapso_ex/blob/v0.1.0/lib/kapso_ex/whatsapp/media.ex#L1)

Upload, inspect, delete and download WhatsApp media.

Size limits set by Meta: images (jpeg, png) 5 MB; video (mp4, 3gp) and
audio (aac, mp3, ogg, opus) 16 MB; documents 100 MB; stickers (webp)
100 KB static or 500 KB animated.

To upload media from a public URL instead of bytes, use
`KapsoEx.Platform.Media.upload/4`.

# `result`

```elixir
@type result() :: {:ok, map()} | {:error, KapsoEx.Error.t()}
```

# `delete`

```elixir
@spec delete(KapsoEx.Client.t(), String.t(), String.t()) :: result()
```

Deletes an uploaded media file.

# `download`

```elixir
@spec download(KapsoEx.Client.t(), String.t(), String.t()) ::
  {:ok, binary()} | {:error, KapsoEx.Error.t()}
```

Downloads the bytes of a media file.

Fetches the metadata with `get/3` and then the signed `download_url`, so
the media must be known to Kapso (inbound media, or outbound media shortly
after it was sent).

    {:ok, bytes} = Media.download(client, media_id, phone_number_id)

# `get`

```elixir
@spec get(KapsoEx.Client.t(), String.t(), String.t()) :: result()
```

Gets media metadata, including a `url` and a short-lived `download_url`
(valid for about 5 minutes).

# `upload`

```elixir
@spec upload(KapsoEx.Client.t(), String.t(), iodata(), keyword()) :: result()
```

Uploads `content` (a binary) and returns its media ID.

## Options

  * `:filename` - required, for example `"photo.jpg"`.
  * `:content_type` - MIME type; inferred from `:filename` when omitted.

## Examples

    {:ok, %{"id" => media_id}} =
      Media.upload(client, phone_number_id, File.read!("photo.jpg"), filename: "photo.jpg")

    Messages.send_image(client, phone_number_id, "56961567267", media_id, caption: "Hi")

# `upload_file`

```elixir
@spec upload_file(KapsoEx.Client.t(), String.t(), Path.t(), keyword()) :: result()
```

Uploads the file at `path`. Options: `:filename` (defaults to the file's
basename) and `:content_type`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
