1

我有处理文件上传的服务器。它处理内存中的文件。处理完成后,我必须将文件上传到下一个服务器。我怎么能做到这一点?

express用来处理文件上传到第一台服务器和restify客户端与第二台服务器通信。

所以我有这样的事情:

app.post('/first-server',function(req,res,next){
    var file_path = req.files.somefile.path;

    var param1 = req.param('param1') + 'modified';
    var param2 = req.param('param2') + 'modified';

    doSomethingWithFile(file_path,function(modified_file_stream){
        // now I want to post file (stream) and modified params (param1 & param2) to second server
    });

});
4

1 回答 1

1

尝试这个:

app.post('YourRoute', function (req, res) {
    var request = require('request');
    req.pipe(request.post('/YourAnotherServerURL/Route:3300')).pipe(res);
});

HTTPRequest是一个流。因此,您实际上可以将当前流通过管道传输到您的下一个服务器;在您的快速路线内。

有关更多信息,请查看

于 2013-09-06T13:17:18.680 回答