将上传的文件stream式传输到HTTP请求

我的目标是接受上传的文件,并使用Wistia Upload API将其传输到Wistia 。 我需要能够添加字段到HTTP请求,我不希望该文件触摸磁盘。 我正在使用Node , Express , Request和Busboy 。

下面的代码有两个console.log语句。 第一个返回[Error: not implemented] ,第二个返回[Error: form-data: not implemented] 。 我是Node新手,所以我可能做了一些根本性的错误。 任何帮助将非常感激。

 app.use("/upload", function(req, res, next) { var writeStream = new stream.Writable(); writeStream.on("error", function(error) { console.log(error); }); var busboy = new Busboy({headers: req.headers}); busboy.on("file", function(fieldname, file, filename, encoding, mimetype) { file.on("data", function(data) { writeStream.write(data); }); file.on("end", function() { request.post({ url: "https://upload.wistia.com", formData: { api_password: "abc123", file: new stream.Readable(writeStream) } }, function(error, response, body) { console.log(error); }); }); }); req.pipe(busboy); }); 

我不熟悉busboy模块,但是你得到的错误是试图使用未实现的stream。 每当你直接从stream模块中创build一个新的可读或可写的stream时,你都必须分别创build_read_write方法Stream Implementors(node.js api) 。 为了给你一些工作,下面的例子是使用multer来处理多部分的请求,我想你会发现MORTER比BUSH更容易使用。

 var app = require('express')(); var fs = require('fs'); var request = require('request'); app.use(multer()); app.post("/upload", function(req, res, next) { // create a read stream var readable = fs.createReadStream(req.files.myfile.path); request.post({ url: "https://upload.wistia.com", formData: { api_password: "abc123", file: readable } }, function(err, res, body) { // send something to client }) }); 

我希望这可以帮助,不幸的是我不熟悉busboy,但是这应该与multer一起工作,正如我之前所说的问题是,你正在使用未实现的stream,我相信有一种方法来configuration这个操作与busboy如果你想。