Using formidable to bypass the fact that nextjs doesn't manage the FormData (in my case to be used when uploading a file)
When calling the root, I'm parsing the body as follows. Files.File is typed as "File | File[]" although I set {multiple=false} when creating the instance of formidable. In my opinion, it should be File only as multiple option is set to false.
But the weird thing is that when consoling the files.file object, it is typed as PersistentFile and not File. And both types are incompatibles....
What is wrong here ?
running "formidable": "^2.0.1", "@types/formidable": "^2.0.0", "typescript": "4.4.4"
export const config = {
api: {
bodyParser: false,
},
};
const handler = async (
req: NextApiRequest,
res: NextApiResponse
): Promise<void> => {
const form = formidable({ multiples: false });
form.parse(
req,
async (_, fields: formidable.Fields, files: formidable.Files) => {
console.log(files.file); <--- shows PersistentFile type in the console (see screenshot #2)
await bucketUpload(
String(fields.bucketName),
files.file,
String(fields.fileName)
);
}
);
res.status(200).json({ text: "Hello" });
};

