Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Guides · File System

Get the MIME type of a file

Read the MIME type Bun infers for a file from the .type property of a BunFile.

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.

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 for more on working with BunFile.