Created
May 17, 2018 02:59
-
-
Save lastday154/68fcff9039e00169f8ea17d2700c665e to your computer and use it in GitHub Desktop.
upload file nodejs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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