So I am having a small error on how to integrate Mongodb GridFS with my NextJS api page - which is designed to upload images as well as create a new document.
The stage that I am stuck at is how do I get the data into MongoDB GridFS.
I am using formidable which is a nodeJS plugin to read form data including FILES.
const form = new formidable.IncomingForm();
//const uploadFolder = path.join(__dirname, 'public','files');
form.uploadDir = "public/files";
form.keepExtensions = true;
form.parse(req, (err, fields, files) => {
var file = files.file
console.log(JSON.stringify(file));
try{
const newFile = File.create({
name:`files\${file.newFilename}.mp3`
});
res.status(200).json({status:'success'});
}
catch(error){
res.send(error);
}
});
The above code works by putting the temp file in public/files directory - So I know I am going to have to read this data?
I am wondering if anyone else has worked with formidable and MongoDB for file uploads.
I posted this question on StackOverflow as well, any help would be great.