middy
middy copied to clipboard
http-multipart-body-parser fails to parse form-data created in node
Form data created in Node has the boundary key set to boundary=----formadata-undici-[numbers]
This format fails the middleware, as the regexp does not include the - character.
How to reproduce the behaviour:
To check the boundary of FormData created by Node:
const form = new Formdata() form.append('foo', 'bar') const req = new Request(new URL('http://to/'), { method: 'POST', body: form }) const contentType = req.headers.get('content-type')
This throws the error Unsupported Media Type
Expected behaviour The middleware is able to handle multipart/form-data from Node.
Environment:
- Node.js: 22
- Middy: 6.1.6
- AWS SDK: 3.617.0
Additional context
For unit testing my project's upload controller. I would like to not have to enable disableContentTypeError as it should only accept form-data. If there is a better way to create a mock event with FormData, please let me know.
I can resolve it by adding a - character to the mimePattern regexp in /http-multipart-body-parser/index.js, not sure if this is the best path forward but can create a pull request if needed with this change.