如何手动从节点应用程序上传文件到服务器

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

我正在使用express处理file upload到第一台服务器,并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 }); }); 

尝试这个:

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

你的HTTPRequest是一个stream。 所以,你实际上可以将当前的stream传送到你的下一个服务器。 在您的快速路线。

欲了解更多信息,请检查