javascript - node fs (filestream) creating 2 files when uploading single file -


i using following code allow people upload images server:

app.post("/api/upload", function (req, res) {    fs.readfile(req.files[0].path, function (err, data) {     console.log('the data file..', data);      if (err) {       res.send(err).end();     } else {       // ...       var newpath = __dirname + "/uploads/" + req.headers["account_id"] + '_' + moment().format('mm_dd_yyyy_hh-mm-ss') + '_' + req.files[0].originalname;       fs.writefile(newpath, data, function (err) {         console.log('file written');         if (err) {           res.send(err).end();         } else {             res.send({             success: true,             file: newpath,             files: req.files           }).end();         }         //res.end({"success": true})       });     }   });   }); 

the problem evey file gets uploaded getting arraybuffer version (i think) see image:

enter image description here

how can prevent this, , of all, why happening? thanks!

it looks me seeing temporary upload file , saved file. code should work fine if add in code delete temporary file (req.files[0].path).


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -