2
我正在努力研究如何获取衍生子进程的输出并将该输出提供给多部分mime上传。将spawn过程的管道输出转换为superagent upload
这里是我有一个据我可以告诉应该工作
var request = require('superagent');
var spawn = require('child_process').spawn;
var spawned = spawn('echo', ['hello', 'world']);
request.post('http://localhost/api/upload')
.attach('file', spawned.stdout)
.end(function(res) {
console.log("DONE", res);
});
不幸的是,这将引发从节点而无益Error: socket hang up
响应。
感谢您的建议。 我重写了你的例子,因为Superagent真的不喜欢用缓冲区而不是Streams。我用下面的代码替换了它:https://gist.github.com/hash-bang/f897f72fa8048ebb315d 这个的确如你所说的那样工作。可惜我找不到用Streams做这项工作的方法。 – 2014-12-21 06:40:56
啊,没有意识到:对不起,< –
rdegges
2014-12-21 20:50:16
你的方法工作正常,只是使用缓冲区而不是Streams。经过多次实验,我仍然无法找到一种方法来完成这项工作。 – 2014-12-21 20:52:43