I try to do simple upload in node.js, So I upload a file via my browser, and my server should get this file.
I have the next methods:
app.post('/saveDocument', function (req, res){
var fileName = req.body.name;
fs.readFile(req.file, function (err, data) {
fs.writeFile("./myStorage/" + fileName, data, function (err) {
});
})
FileServer.prototype.returnRes(res, 200);
});
and my HTML is:
<html>
<head>
<title>Upload Example</title>
</head>
<body>
<form id="uploadForm"
enctype="multipart/form-data"
action="/saveDocument"
method="post">
<input type="file" id="userPhotoInput" name="displayImage" />
<input type="submit" value="Submit">
</form>
<span id="status" />
<img id="uploadedImage" />
</body>
</html>
I get the next error: TypeError: path must be a string
What I do wrong?