Skip to content

Bug: Bun server loses File MIME type when reading request body as Blob #32801

Description

@dinwwwh

What version of Bun is running?

1.3.14

What platform is your computer?

Linux 6.17.0-35-generic x86_64 x86_64

What steps can reproduce the bug?

When a File object with a custom MIME type (e.g. application/json;charset=utf-8)
is sent as a POST body, calling request.blob() on the server returns a Blob whose
.type is reset to text/plain;charset=utf-8 instead of preserving the original type.

Affected: Bun (tested on latest)
Expected: blob.type === 'application/json;charset=utf-8'
Received: blob.type === 'text/plain;charset=utf-8'

import * as assert from 'node:assert'
import { sleep } from 'bun'

let file: Blob

const server = Bun.serve({
  async fetch(request) {
    file = await request.blob()

    return new Response('OK')
  },
  port: 0,
})

const res = await fetch(`http://localhost:${server.port}`, {
  method: 'POST',
  body: new File(['"name"'], 'file.json', { type: 'application/json;charset=utf-8' }),
})

await sleep(1000) // delay between client and server

console.log(file!.type)
assert.equal(file!.type, 'application/json;charset=utf-8')
// Expected: "application/json;charset=utf-8"
// Received: "text/plain;charset=utf-8"

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions