# `FileType`

A file's media type: `image/png`, `application/pdf` and so on.

Use it to say which kinds of file an upload accepts.

## Shape

One of these 8 values:

| Value | Written |
|---|---|
| `FileType.png` | `image/png` |
| `FileType.jpeg` | `image/jpeg` |
| `FileType.webp` | `image/webp` |
| `FileType.pdf` | `application/pdf` |
| `FileType.csv` | `text/csv` |
| `FileType.tsv` | `text/tab-separated-values` |
| `FileType.json` | `application/json` |
| `FileType.json_lines` | `application/jsonl` |

## Example

```jadpo
FileType.png
```

`text.parse(raw, as: FileType)` reads one from text that comes from outside. Text that isn't one at all fails `malformed`, such as `png` or `image/tiff`.

## Good to know

- It holds a fixed list. Any other media type, such as `image/tiff`, is refused.
- `==` tells you whether two are the same. `<` and `list.sort_by` don't take it.

## In JSON

A string, in a request, a response or `json.write`:

```json
"image/png"
"application/pdf"
```

## Details

<details>
<summary>Text form, storage, how it is shown, and operations</summary>

`FileType` is in the group Web and network, and has been in Jadpo since 0.1.0.

### Text form

`text.from` writes one standard text form, the same form `text.parse` reads back: `image/png` and `application/pdf`.

### How it is stored

It is stored in one column named for the field, of type `text`. `application/pdf` is stored as `'application/pdf'`.

### How it is shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `image/png` | `image/png` |
| `application/pdf` | `application/pdf` |

### Operations

It also takes `text.parse`, `text.from`, `text.format`, `json.read`, `json.write` and `==`. [How every standard type behaves](/docs/every-standard-type-meets-one-contract.md) says how they work.

</details>
