I get "Response body object should not be disturbed or locked" in a POST request with FormData
Answered
Dutch posted this in #help-forum
DutchOP
Here is the request from the client:
And here is the Route handler:
Error when i call the fetch request on a button click:
let formData = new FormData()
formData.append('name', 'someone')
await fetch('/api/crop', {
method: 'POST',
body: formData, // If i add a plain object it works: JSON.stringify({name: "someone"})
})And here is the Route handler:
// api/crop/route.ts
import { NextRequest, NextResponse } from 'next/server'
export async function POST(): Promise<NextResponse> {
console.log("here") // won't be logged
return NextResponse.json({success: true })
}Error when i call the fetch request on a button click:
⨯ TypeError: Response body object should not be disturbed or locked
at extractBody (node:internal/deps/undici/undici:6433:17)
at new Request (node:internal/deps/undici/undici:7314:48)`Answered by Dutch
Yes this was the full code. I found the issue. It's more related to payload cms, not next.
2 Replies
@Ray is it the full code of the route handler?
DutchOP
Yes this was the full code. I found the issue. It's more related to payload cms, not next.
Answer