# Auto-detect MIME types on upload

> Learn how to use Bitiful's automatic MIME type detection for your files.

## Let Bitiful S4 detect object MIME types automatically

> **Tip**
>
> In 2024, we improved detection of **M2TS** and **M4S** video segment types to help you defend against increasingly common **resource abuse attacks**.

In the best practice "[Upload files securely from the client](/en/best-practice/web-uploads)", the JavaScript snippet at the end deliberately forces `Content-Type` to empty, because:

- When axios sends a PUT request, it adds a `Content-Type` of `application/x-www-form-urlencoded` by default, which differs from what S3 expects for `Content-Type` on a PUT.
- In the S3 protocol, if you include the file's MIME type as `Content-Type` when uploading, it's saved as metadata in the S3 backend (telling S3 what MIME type the uploaded object is).

So the ideal approach might seem to be setting `Content-Type` to the MIME type of the file being uploaded, for example:

```Javascript
                const config = {
                    headers: {
                        'Content-Type': 'image/jpeg',
                    },
                };
```

With AWS or OSS, the best you can do is probably to write reliable file-type detection in JavaScript, and tell the server which MIME type you intend to upload when you request the presigned URL:

```Javascript
        const url = `/s3_upload_url`;
        const params = {key: '1.jpg', mime: 'image/jpeg'};
```

With Bitiful S4, you have a **better** option:

**`When Bitiful S4 receives an upload request with an empty Content-Type, it automatically determines the file's MIME type from both its extension and its bytes.`**

> In AWS S3 and OSS, every such object becomes "application/octet-stream".

Unlike `file.type` in JavaScript, which relies only on the file extension, handing MIME detection over to S4 is more reliable and accurate.

All you need to do is:

1. **Delete your MIME detection code.**
2. **Set Content-Type to null when you send the PUT request.**
