如何在javascript中使用createwriteStream

时间:2015-02-13 04:03:50

标签: javascript node.js stream fs

我如何发送文件,服务器用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);

我在console linux中使用此命令: curl --upload-file hello.txt 127.0.0.1:3000并且工作正常,但我不知道如何使用url发送文件

有人知道吗?

1 个答案:

答案 0 :(得分:-1)

curl -i -F name = test -F filedata =@localfile.jpg 127.0.0.1:3000