var http = require('http');
var fs = require('fs').createWriteStream('file1');;
http.createServer(function(req, res) {
// This opens up the writeable stream to `output`
// This pipes the POST data to the file
req.pipe(fs);
// After all the data is saved, respond with a simple html form so they can post more data
req.on('end', function () {
res.writeHead(200, {"content-type":"text/html"});
res.end('<form method="POST"><input name="test" /><input type="submit"></form>');
});
// This is here incase any errors occur
fs.on('error', function (err) {
console.log(err);
});
}).listen(8080);
在上面的代码中,我试图使用 POST 方法接受来自 HTML 表单的输入,并将其通过管道传输到文件的写入流中,但我无法实现并且正在显示以下错误
{ [Error: EBADF, close] errno: 9, code: 'EBADF' }
{ [Error: EBADF, close] errno: 9, code: 'EBADF' }
{ [Error: EBADF, close] errno: 9, code: 'EBADF' }
{ [Error: EBADF, close] errno: 9, code: 'EBADF' }
{ [Error: EBADF, close] errno: 9, code: 'EBADF' }
{ [Error: EBADF, close] errno: 9, code: 'EBADF' }
{ [Error: EBADF, close] errno: 9, code: 'EBADF' }
{ [Error: EBADF, close] errno: 9, code: 'EBADF' }
{ [Error: EBADF, close] errno: 9, code: 'EBADF' }
出了什么问题,我应该做些什么修改才能成功地将数据从 POST 重定向到文件中?我在使用可写流写入文件时阅读了这篇相关的帖子Node.js EBADF 错误
但是还是找不到出路,我是NODEJS新手,请帮帮我。谢谢...