在supabase上传文件:error RequestInit: duplex选项在发送正文时是必需的



我正在尝试用node.js上传supabase上的文件,我得到这个错误:RequestInit:发送消息体时需要双工选项。我不知道这是什么意思。我在代码中做错了什么?

router.post("/", async (req, res) => {
const datosForm = req.body;

const supabase = createClient(
process.env.SUPABASE_URL,
process.env.SUPABASE_KEY
);
const form = formidable({
multiples: false,
//uploadDir: "public/images",
keepExtensions: true,
})
//await form.parse(req)
form.parse(req, async(err, fields, files) => {
if (err) {
console.log("error: " + err);
} else {
console.log("files: ", files.foto.newFilename);
let imagePath;
try {
const mascotaDB = new Mascota(fields);
if(files.foto.originalFilename != ""){
const ext = path.extname(files.foto.filepath);
const newFileName = "image_"+Date.now()+ext;
console.log("newFileName: ", newFileName);
try{
const{data, error}=await supabase.storage.from("articulos").upload(
newFileName,    
fs.createReadStream(files.foto.filepath),   
{
cacheControl: '3600',
upsert: false,     
contentType: files.foto.type,  
}
);                    
imagePath = newFileName;
console.log("path: ", imagePath);
console.log("mascota: ", imagePath);
mascotaDB.path=imagePath;

await mascotaDB.save()

res.redirect("/articulos") 
}catch(err){
console.log("error: "+err);
}

}


} catch (error) {
console.log(error)
}
}

})

});

我没有得到我试图上传到supabase中创建的桶中的图像

具体错误是指这个

在请求中,init参数需要属性"duplex": "half"

可能你的NodeJS版本导致了这个问题,如下所示:https://github.com/nodejs/node/issues/46221

最新更新