【发布时间】:2015-04-14 01:32:18
【问题描述】:
我如何发送文件以便服务器使用 fs.createwriteStream(); 读取它
var http = require('http');
var fs = require('fs');
http.createServer(function(req, res) {
// This opens up the writeable stream to `output`
var writeStream = fs.createWriteStream('./output');
// This pipes the POST data to the file
req.pipe(writeStream);
req.on('end', function () {
res.end('ok upload file');
});
// This is here incase any errors occur
writeStream.on('error', function (err) {
console.log(err);
});
}).listen(8080);
我在控制台 linux 上使用这个命令: curl --upload-file hello.txt 127.0.0.1:3000 并且工作正常,但我不知道如何使用 url 发送文件
有人知道吗?
【问题讨论】:
-
我看到这个视频youtube.com/watch?v=zyf-TdYz1fo 并认为可以
标签: javascript node.js stream fs