ReadableStream { locked: false, state: 'readable', supportsBYOB: false }



我的代码中有一个错误,我得到以下消息:"ReadableStream {locked: false, state: 'readable', supportsBYOB: false}"。有人知道这个错误意味着什么,我怎么能解决它吗?我使用下一个13,并试图发送数据到mongodb中的数据库后查询。这是我的代码:

export async function POST (req, res) {
const { nombre, apellido, id, age, direc, cell, email, pass, confirmPass } = req.body
try {
const newUser = new User({
nombre,
apellido,
id,
age,
direc,
cell,
email,
pass,
confirmPass
})
const savedUser = await newUser.save()
console.log(savedUser)
const responseBody = { body: savedUser }
const response = new Response(responseBody, { headers: { 'Content-Type': 'application/json' } })
return response
} catch (error) {
return new Response({ status: 500 }, { error: error.message })
}
}

我使用thunderClient发出请求,响应是:[object Object]

我试过json。解析和json。字符串化,设置头和req.on

这将解决您的问题

const body = await request.json();

似乎你没有很好地解析数据你试过使用body-parser吗?

如果有人试图从FormData中获取图像,那么使用这个…

const images = await req.formData();
//the formData will be your formData name which you send it from frontend

req.json()确实有效,例如,与JSON.parse()相反。但是这个方法在它们自己的NextApiRequest中不存在,所以TypeScript会抛出一个错误。

相关内容

最新更新