【问题标题】:how use createwriteStream with javascript如何将 createwriteStream 与 javascript 一起使用
【发布时间】: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 发送文件

有人知道吗?

【问题讨论】:

标签: javascript node.js stream fs


【解决方案1】:

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

【讨论】:

  • 但是有javascript朋友
猜你喜欢
  • 1970-01-01
  • 2016-05-31
  • 1970-01-01
  • 2016-05-27
  • 1970-01-01
  • 1970-01-01
  • 2022-12-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多