superagentを介してクライアントからのストリームファイルをサードパーティにパイプするためのmulterミドルウェアを作成しようとしています。スーパーエージェントを使用した読み込み可能なストリームのパイプ
const superagent = require('superagent');
const multer = require('multer');
// my middleware
function streamstorage(){
function StreamStorage(){}
StreamStorage.prototype._handleFile = function(req, file, cb){
console.log(file.stream) // <-- is readable stream
const post = superagent.post('www.some-other-host.com');
file.stream.pipe(file.stream);
// need to call cb(null, {some: data}); but how
// do i get/handle the response from this post request?
}
return new StreamStorage()
}
const streamMiddleware = {
storage: streamstorage()
}
app.post('/someupload', streamMiddleware.single('rawimage'), function(req, res){
res.send('some token based on the superagent response')
});
私はこれが動作しているようだと思うが、私はたSuperAgent要求から受信したトークンを返す必要があるため、たSuperAgent POST
要求からの応答を処理するかどうかはわかりません。
私はpost.end(fn...)
を試しましたが、明らかにend
とpipe
can't both be used togetherです。私はパイピングの仕組みを誤解しているような気がしています。
これは意味があります。私は現在最初の提案をしているので、私は2番目の解決策を試してみましょう。 –