23 lines
562 B
Plaintext
23 lines
562 B
Plaintext
---
|
|
title: Get the MIME type of a file
|
|
sidebarTitle: Get MIME type
|
|
mode: center
|
|
---
|
|
|
|
The `Bun.file()` function accepts a path and returns a `BunFile` instance. The `BunFile` class extends `Blob`, so use the `.type` property to read the MIME type.
|
|
|
|
```ts
|
|
const file = Bun.file("./package.json");
|
|
file.type; // application/json;charset=utf-8
|
|
|
|
const html = Bun.file("./index.html");
|
|
html.type; // text/html;charset=utf-8
|
|
|
|
const image = Bun.file("./image.png");
|
|
image.type; // image/png
|
|
```
|
|
|
|
---
|
|
|
|
See [File I/O](/runtime/file-io) for more on working with `BunFile`.
|