Skip to content

Instantly share code, notes, and snippets.

@lastday154
Created May 17, 2018 02:59
Show Gist options
  • Select an option

  • Save lastday154/68fcff9039e00169f8ea17d2700c665e to your computer and use it in GitHub Desktop.

Select an option

Save lastday154/68fcff9039e00169f8ea17d2700c665e to your computer and use it in GitHub Desktop.
upload file nodejs
const form = new formidable.IncomingForm();
form.parse(req, (err, fields, files) => {
const oldPath = files.file.path;
const newPath = path.join(process.cwd(), '/uploads/', files.file.name);
fs.rename(oldPath, newPath, (errRn) => {
if (errRn) {
res.status(500);
res.json({ success: false });
return;
}
csvToJson(newPath);
res.setHeader('Access-Control-Allow-Origin', '*');
res.status(200);
res.json({ success: true });
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment