mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
23 lines
555 B
Plaintext
23 lines
555 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
|
|
|
|
const file = Bun.file("./index.html");
|
|
file.type; // text/html
|
|
|
|
const file = Bun.file("./image.png");
|
|
file.type; // image/png
|
|
```
|
|
|
|
---
|
|
|
|
Refer to [API > File I/O](/runtime/file-io) for more information on working with `BunFile`.
|