-
I 'am a newbie programmer. Today I want to install and configuration formidable for my project. https://www.npmjs.com/package/formidable I have question: where I find information about how to save files to dir? I see on npmjs example code with express.js, but in this code not include information about save, documentation also not included information about save files to dir. How I should read that documentation like this? I will be grateful for any comments, probably at the moment I don't think like programmer. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
First, welcome to programming! |
Beta Was this translation helpful? Give feedback.
-
@robokonk with passing |
Beta Was this translation helpful? Give feedback.
-
You can use code like this (code from my NextJS app): const post = async (req, res) => {
const form = new formidable.IncomingForm();
form.parse(req, async function (err, fields, files) {
try{
await saveFile(files.file);
}
catch(e){
console.log('Error: ',e);
}
return res.status(201).send("Nothing");
});
};
const saveFile = async (file) => {
const data = fs.readFileSync(file.filepath);
fs.writeFileSync(`./public/${file.originalFilename}`, data);
await fs.unlinkSync(file.filepath);
return;
}; |
Beta Was this translation helpful? Give feedback.
You can use code like this (code from my NextJS app):