Thursday, 13 April 2017

Getting this typeerror while uploading in node js

this is what i am getting as an error

TypeError: Cannot read property 'file' of undefined
    at C:\node\project\server.js:17:25
    at Layer.handle [as handle_request] (C:\node\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\node\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\node\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\node\node_modules\express\lib\router\layer.js:95:5)
    at C:\node\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (C:\node\node_modules\express\lib\router\index.js:335:12)
    at next (C:\node\node_modules\express\lib\router\index.js:275:10)
    at Immediate.<anonymous> (C:\node\node_modules\multer\lib\make-middleware.js:53:37)
    at runCallback (timers.js:670:20)

my html code

     <form action = "http://127.0.0.1:8081/file_upload" method = "POST" 
     enctype = "multipart/form-data">
     <input type="file" name="file" size="50" />
     <br />
     <input type = "submit" value = "Upload File" />
  </form>

my js code

   console.log(req.file.file.name);console.log(req.file.file.path console.log(req.file.file.type);var file = __dirname + "/" + req.file.file.name;

where im doing wrong?



via Jana

No comments:

Post a Comment