superagent을 통해 클라이언트에서 스트리밍 된 파일을 제 3 자에게 파이프하기 위해 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')
});
나는이 작동하는 것 같다 생각하지만 내가 슈퍼 에이전트 요청에서받은 토큰을 반환해야하기 때문에, 슈퍼 에이전트 POST
요청의 응답을 처리하는 방법을 모르겠어요.
나는 post.end(fn...)
을 시도했지만 분명히 end
과 pipe
can't both be used together을 시도했습니다. 나는 파이핑이 어떻게 작동하는지 오해하고있는 것처럼 느껴진다. 그렇지 않으면 내가하려는 것은 실용적이다.
의미가 있습니다. 저는 현재 첫 번째 제안을하고 있습니다. 그래서 저는 두 번째 해결책을 시도 할 것입니다. –