javascript - Upload file to Node.js with HTML -
i'm trying make api upload file using node.js server. undefined
response.
i following tutorial https://www.youtube.com/watch?v=utfz-5wkpro
node.js:
var express = require('express'); var app = express(); var bodyparser = require('body-parser'); app.use(bodyparser.json()); app.post("*", function(req, res) { res.end(json.stringify(req.files) + "\n"); }); console.log("server @ 8080"); app.listen(8080);
html
<html> <head> <form method="post" enctype="multipart/form-data" action="http://localhost:8080"> <input type="file" name="myimage" /> <input type="submit" name="submit" value="submit"/> </form> </head> </html>
after clicking submit got undefined
response.
bodyparser.json()
… you've set parser json formatted requests
enctype="multipart/form-data"
… aren't making json formatted request.
see the documentation body-parser:
this not handle multipart bodies, due complex , typically large nature. multipart bodies, may interested in following modules:
… followed list of suggestions.
pick module can handle multipart requests , use instead of current choice.
Comments
Post a Comment