javascript - Upload files with node.js -
I have this code to upload files with Node.js: Here is the HTML file: When I upload files, I give this next error: what could be the reason I recommend using horrible modules to upload files in Express
application. Use (express.bodyParser ()); // or, as the `req.files` is only provided by multipart middleware, you can add // if you are not worried about parsing non-multipartual uploads, like // like: app .use (express.multipart ()); App.get ('/', function (request, race) {fs.readFile ('uploadHTML.html', function (hey, data) {res.writeHead (200, {'content-type': 'text / html' , 'Content-length': data.length}); res.write (data); res.end ();});}); App.post ('/ upload', function (req, res) {console.log (req.files); fs.readFile (req.files.displayImage.path, function (mistake, data) {// ... var Newpath = __dirname; fs.writeFile (Newpath, data, function (mistake) {res.redirect ("back");});});});
& lt; Html & gt; & Lt; Top & gt; & Lt; Title & gt; Upload an example & lt; / Title & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt; Form id = "uploadform" enctype = "multipart / form-data" action = "/ upload" method = "post" & gt; & Lt; Input type = "file" id = "userphotoInput" name = "displayImage" /> & Lt; Input type = "submit" value = "submit" & gt; & Lt; / Form & gt; & Lt; span id = "status" / & gt; & Lt; Img id = "uploaded image" /> & Lt; / Body & gt; & Lt; / Html & gt;
Type error: 'displayImage' on property can not be read : \ NodeInstall \ Nodejs \ express.js: 42: 22 callback (c: \ NodeInstall \ nodejs \ node_modules \ express \ lib \ router \ index.js: 164: 37) Ultimate (c: \ NodeInstall \ nodejs \ node_modules \ express \ Router \ index.js: 138: 11) pass (c: \ NodeInstall \ nodejs \ node_modules \ express \ lib \ router \ index.js: 145: 5) on router ._dispatch (c: \ NodeInstall \ nodejs \ Node_module \ N \ "\ N \" \ nodeInstall (c: \ NodeInstall \ nodejs \ node_modules \ express \ lib \ router \ index.js: 33: 10) next (c: \ NodeInstall) \ Object \ router \ c : \ Express \ lib \ router \ index.js: 173: 5) \ Nodejs \ node_mo Dules \ express \ node_modules \ connect \ lib \ proto.js: 193: 15) [handle] on Object.expressInit (c: \ NodeInstall \ nodejs \ node_modules \ express \ lib \ middleware.js: 30: 5) at next ( C: \ Handheld on Object.query (c: \ NodeInstall \ nodejs \ node_modules \ express \ node_moduleules \ C: \ NodeInstall \ nodejs \ node_modules \ express \ node_modules \ express \ node_modules \ connect \ lib \ proto.js: 193: \ Middle \ lib connect \ dleware \ query.js: 45:? 5)
var fileupload = require ('fileupload'). CreateFileUpload ('/ uploadDir') with reference to other form fields // files also uploaded to 'uploaddir', fileupload, function (request, resolution) {// files specified) with req .body are now in the object}}
Comments
Post a Comment