h3-formidable icon indicating copy to clipboard operation
h3-formidable copied to clipboard

Does not work with middleware: Cannot destructure property 'files' of 'event.context.formidable' as it is undefined

Open MickL opened this issue 1 year ago • 0 comments

I tried both copying the readme and the stackblitz example 1 to 1 but I get the following error:

[nuxt] [request error] [unhandled] [500] Cannot destructure property 'files' of 'event.context.formidable' as it is undefined.

I double checked everything and cant figure out the problem.

middleware/formidable.ts

import { createFileParserMiddleware } from 'h3-formidable'

export default createFileParserMiddleware({
  // formidable options
})

api/upload.ts

export default eventHandler(async (event) => {
  const { files } = event.context.formidable
})

In contrast using no middleware works:

import { readFiles } from 'h3-formidable'

export default eventHandler(async (event) => {
  const { fields, files, form } = await readFiles(event, {
    // formidable options
    // https://github.com/node-formidable/formidable#options
  })
})

Nuxt: 3.9.0

MickL avatar Dec 26 '23 10:12 MickL