Skip to content

Cannot read an uploaded file with express + multer since 6.4.0 #337

@ghostd

Description

@ghostd

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the regression has not already been reported

Last working version

6.3.0

Stopped working in version

6.4.0

Node.js version

22.13.1

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

MacOS 15.3

💥 Regression Report

I tried to upgrade light-my-request from 6.3.0 to 6.5.1 and my tests containing uploads now fail (they also fail with version >= 6.4.0)

With the provided sample, it get the following error:

Cannot read properties of undefined (reading 'buffer')

It seems multer fail to read the multipart data with the last version of light-my-request.

express: 4.21.2
multer: 1.4.5-lts.1

Steps to Reproduce

Here is a simple test i have (using vitest):

it("should return the file content", async () => {
    const multerMiddleware = multer({
        storage: multer.memoryStorage(),
        limits: {
            fileSize: 1024,
        },
    })

    const app = express()

    app.post("/hello", multerMiddleware.single("textFile"), (req, res) => {
        res.send(req.file.buffer.toString("utf8"))
    })
    app.use((err, req, res, next) => {
        console.warn(err)
        res.status(500).send("Something was wrong")
    })

    const formData = new FormData()
    formData.append("textFile", new Blob(["some data"]), "sample.txt")

    const response = await LightMyRequest.inject(app, {
        method: "POST",
        url: "http://example.com:8080/hello",
        payload: formData,
    })

    expect(response.statusCode).toEqual(200)
    expect(response.payload).toEqual("some data")
})

Expected Behavior

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions