h3 icon indicating copy to clipboard operation
h3 copied to clipboard

readMultipartFormData method error on Netlify

Open besscroft opened this issue 2 years ago • 3 comments

Environment

Node Version: v18.18.0

Reproduction

https://github.com/besscroft/kamera/blob/dev/server/api/uploadFile.post.ts

Describe the bug

When I requested this interface, an error message appeared. I'm running fine on Windows 11 and Vercel, but I'm getting errors with Netlify.

export default defineEventHandler(async (event) => {
    const body = await readMultipartFormData(event)
    console.log('body', body)
})

On Windows 11 and Vercel, body gets the correct content, but on Netlify, body is []. I tried a few things but couldn't solve the problem.

Finally, thank you for taking the time to read my question, thank you!

Additional context

I think the problem lies here: return parseMultipartData(body, boundary); `ORH W8S 5RMYUI$MH0BJ}V

Logs

Dec 4, 10:03:40 PM: d6a18e95 INFO   contentType multipart/form-data; boundary=----WebKitFormBoundaryxFcO1w3Pn2alJ4z3
Dec 4, 10:03:40 PM: d6a18e95 INFO   boundary ----WebKitFormBoundaryxFcO1w3Pn2alJ4z3
Dec 4, 10:03:40 PM: d6a18e95 INFO   rawBody <Buffer 4c 53 30 74 4c 53 30 74 56 32 ......
Dec 4, 10:03:40 PM: d6a18e95 INFO   body []
Dec 4, 10:03:40 PM: d6a18e95 ERROR  [nuxt] [request error] [unhandled] [500] Cannot read properties of undefined (reading 'data')
Dec 4, 10:03:40 PM: d6a18e95 ERROR    at ./chunks/uploadFile.post.mjs:37:24
Dec 4, 10:03:40 PM: d6a18e95 ERROR    at async Object.handler (./chunks/nitro/netlify.mjs:2444:19)
Dec 4, 10:03:40 PM: d6a18e95 ERROR    at async toNodeHandle (./chunks/nitro/netlify.mjs:2633:7)
Dec 4, 10:03:40 PM: d6a18e95 ERROR    at async lambda (./chunks/nitro/netlify.mjs:5604:13)

besscroft avatar Dec 04 '23 14:12 besscroft

Related questions: https://github.com/nuxt/nuxt/issues/24587

besscroft avatar Dec 04 '23 14:12 besscroft

I have the same issue... Locally everything works fine, but I log an empty array on netlify.

BenGoetemann avatar Jan 03 '24 00:01 BenGoetemann

I have the same issue... Locally everything works fine, but I log an empty array on netlify.

I get the same thing you are getting. It works fine locally when I deploy to cloudflare it's just an empty array.

fadeaway avatar Aug 01 '24 17:08 fadeaway

Is there a solution to this problem I'm also having the same issue. What can I use instead?

yocheved avatar Mar 24 '25 19:03 yocheved

Is there a solution to this problem I'm also having the same issue. What can I use instead?

possibly NuxtHub blob?

fadeaway avatar Mar 24 '25 22:03 fadeaway

Cannot reproduce.

You may check this example: https://github.com/kricsleo/repro-h3-590 I copied your package.json and lock file, so the dependencies should be the same. And pinned Node.js to v18.18.0.

Deployed on Netlify: https://clever-cajeta-99ce4c.netlify.app/

It successfully parsed the body and returned the expected result.

Image

kricsleo avatar Apr 23 '25 10:04 kricsleo

(closing as there is lack of reproduction)

pi0 avatar Jun 04 '25 22:06 pi0