I have written a node.js server to accept file.
app.post('/', function(req, res) {
console.log(req.files);
fs.readFile(req.files.displayImage.path, function (err, data) {
var newPath = __dirname + "/"+req.files.displayImage.name;
fs.writeFile(newPath, data, function (err) {
if (err) throw err;
res.redirect("back");
});
});
});
This works perfect with HTML form which is
<form action="http://localhost/", method="post", enctype="multipart/form-data">
<input type="file", name="displayImage">
<input type="submit", name="Upload">
But I want to remove HTML UI and want to have node.js code to automatically consume file. I am OK to have file as hard-coded path.
I need a node.js script which can call server code and send a file to upload.
Any help?