# Media

How images, video, audio and other files are linked, with their media type and metadata.

The `Media` structure points to a file, such as a User's avatar or an attachment to a Note, together with what a receiver needs to know before fetching it.

## Definition

**Fields**

- `url` (`URI`, required): Where to fetch the file from.
- `media_type` (`string`, required): [Media type](https://www.iana.org/assignments/media-types/media-types.xhtml) of the file, such as `image/png`. Fields that hold media say which media types they accept.
- `description` (`string`): A human-readable description of the file. Also known as `alt` text.
- `size` (`number`, integer): Size of the file in bytes. Senders **SHOULD** include it.
- `hash` (`string`): SHA-256 hash of the file. **MUST** be encoded in lowercase hexadecimal. Senders **SHOULD** include it.
- `thumbhash` (`string`): Image in [ThumbHash](https://evanw.github.io/thumbhash/) format, encoded in base64 using the standard alphabet with padding, as defined in [RFC 4648, section 4](https://datatracker.ietf.org/doc/html/rfc4648#section-4). Senders **SHOULD** include it for images and video.
- `width` (`number`, integer): Width of the image or video in pixels. Senders **SHOULD** include it for images and video.
- `height` (`number`, integer): Height of the image or video in pixels. Senders **SHOULD** include it for images and video.
- `duration` (`number`, float): Duration of the audio or video in seconds. **MUST NOT** be negative.

```jsonc title="Image"
{
    "url": "https://cdn.example.com/attachments/ece2f9d9-27d7-457d-b657-4ce9172bdcf8.png",
    "media_type": "image/png",
    "description": "A jolly horse running through mountains",
    "size": 453933,
    "hash": "91714fc336210d459d4f9d9233de663be2b87ffe923f1cfd76ece9d06f7c965d",
    "thumbhash": "3OcRJYB4d3h/iIeHeEh3eIhw+j2w",
    "width": 1920,
    "height": 1080
}
```
