# Fix - Converting file types to media types

As was said before, the comparison is made not with **file types** (extensions), but with **media types**. For example, the file type "png" corresponds to the media type "image/png". So, the check succeeded merely due to **coincidence**. File types are not always included in their respective media types. To fix this, we'll use the [mime-types](https://www.npmjs.com/package/mime-types) library to get the media type of a file type. It is already installed, we just need the typing.

```sh
yarn add -D @types/mime-types
```

Above the <mark style="color:blue;">`createFileValidators()`</mark> function, we may create an auxiliary function that:

* Obtains the media types from the <mark style="color:blue;">`fileTypes`</mark> by using the <mark style="color:blue;">`lookup()`</mark> function from **mime-types**
* Creates the regex for validating the media types

```typescript
const createFileTypeRegex = (fileTypes: FileType[]) => {
  const mediaTypes = fileTypes.map((type) => lookup(type));
  return new RegExp(mediaTypes.join('|'));
};
```

Then, use it when creating the regex.

```typescript
const fileTypeRegex = createFileTypeRegex(fileTypes);
```

<mark style="color:green;">**Commit**</mark> - Validating media types instead of extensions
