meabed / graphql-upload-ts

Middleware and an Upload scalar to add support for GraphQL multipart requests (file uploads via queries and mutations) to various Node.js GraphQL servers.
MIT License
42 stars 2 forks source link

Busboy dependency is expecting the Content-Type header key to be in lowercase. #309

Open hafaiedhmehdy opened 3 months ago

hafaiedhmehdy commented 3 months ago

Next.js API routes using graphql-upload-ts may encounter a "Missing Content-Type" error due to a case-sensitivity issue in the underlying Busboy dependency. Normalizing the Content-Type header before passing it to Busboy will resolve this issue.

hafaiedhmehdy commented 3 months ago

Busboy has another major issue where it looks for the Content-Type header incorrectly. In busboy/lib/index.js:53:11, it uses cfg.headers['content-type'], which will always return undefined. The correct way to retrieve the Content-Type header in Next.js is by using req.headers.get('content-type'). Just tagging you in jaydenseric, since it's your original project. And perhaps pass this down to the busboy team.

Edit: it's quite a mess, Next.js API's too different. :'( Another update: I'll be working towards achieving full compatibility between this repository's goal/function and Next.js.

hafaiedhmehdy commented 3 months ago

This solution addresses several issues, including the "Missing Content-Type" error caused by case-sensitivity in Busboy. My implementation ensures compatibility and smooth file upload functionality in Next.js environments.

This is an alpha version, and I'm looking for feedback and criticism to help improve it further. It's currently missing acknowledgements, so I welcome people to add themselves before I do, as I'm quite busy.

You can check out the solution here: graphql-upload-nextjs.