Need your help, I have xhr post request: xhr.send(form.file.files[0]); I'm trying to upload this file to my server in this way :
require('http').createServer(function(req, res) {
let pathname = decodeURI(url.parse(req.url).pathname);
let file = new fs.ReadStream(req);
let path = fs.createWriteStream(__dirname + '/files' + pathname);
file.pipe(path);
file.on('error', function(err) {
console.log(err);
endConnection(res, 500, 'Server Error');
});
res.on('close', file.destroy.bind(file));
}
The main problem is on line new fs.ReadStream(req); - the argument for ReadStream can contain only string, but req is an object. How can I get uploaded file content from the req?