We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
You can use this code.
import formidable from "formidable"; import fs from "fs"; export const config = { api: { bodyParser: false } }; const post = async (req, res) => { console.log('handling file...'); const form = new formidable.IncomingForm(); form.parse(req, async function (err, fields, files) { if (err) console.error(err); console.log(files.file.newFilename); try{ await saveFile1(files.file); } catch(e){ console.log('Error was catched: ',e); } return res.status(201).send("Nothing"); }); }; const saveFile1 = async (file) => { console.log(file); //**TypeError** const data = fs.readFileSync(file.filepath); fs.writeFileSync(`./public/${file.originalFilename}`, data); //await fs.unlinkSync(file.path); return; }; export default (req, res) => { req.method === "POST" ? post(req, res) : req.method === "PUT" ? console.log("PUT") : req.method === "DELETE" ? console.log("DELETE") : req.method === "GET" ? console.log("GET") : res.status(404).send(""); };
TypeError: Cannot read properties of undefined (reading 'newFilename')
Working app.
The text was updated successfully, but these errors were encountered:
Workaround: Apply patch from my PR #890
Sorry, something went wrong.
No branches or pull requests
Support plan
Context
What are you trying to achieve or the steps to reproduce?
You can use this code.
What was the result you got?
TypeError: Cannot read properties of undefined (reading 'newFilename')
What result did you expect?
Working app.
The text was updated successfully, but these errors were encountered: