Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
ghostd opened this issue Feb 9, 2025 · 0 comments · May be fixed by #338
Open
2 tasks done

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

ghostd opened this issue Feb 9, 2025 · 0 comments · May be fixed by #338

Comments

@ghostd
Copy link

ghostd commented Feb 9, 2025

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

mcollina added a commit that referenced this issue Feb 11, 2025
Fixes: #337
Signed-off-by: Matteo Collina <[email protected]>
@mcollina mcollina linked a pull request Feb 11, 2025 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant