1

I am using the code below to upload file-

Code:

app.post('/file_upload', function(req,res){ console.log('FIRST TEST: ' + JSON.stringify(req.files.theFile.name)); console.log('second TEST: ' +req.files.theFile.name); fs.readFile(req.files.theFile.path, function (err, data) { var newPath = "/tmp/"+req.files.theFile.name; var fileName = req.files.theFile fs.writeFile(newPath, data, function (err) { res.send("hi"); }); }); }); 

and i am getting Error:

TypeError: Cannot read property 'thumbnail' of undefined

Please guide me how to solve this.

1
  • 2
    do you want to upload a file, or receive a file? Please post the part of your code that contains the error. Commented Feb 20, 2016 at 11:35

1 Answer 1

3

According to your codes posted in your question, it is hard to figure out the root cause of error. Here is one sample to upload file which I used before, please try it.

app.post('/upload/create', function(req, res){ //save the upload file to folder tmp/ var tmppath = req.files.file.path; var targetpath = '/tmp/'+req.files.file.name; fs.rename(tmppath, targetpath, function(err){ if (err) throw err; fs.unlink(tmppath, function(){ if (err) throw err; console.log('upload file successfully...'); }); }); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.