通过节点代理上传文件

时间:2015-04-16 13:16:25

标签: node.js file-upload

我正在使用节点代理服务器将API请求转发到另一台服务器。这工作正常,但不适用于文件上传。显然,标题设置正确,但不知何故,图像不会被处理到" final"服务器。我该怎么办?。谢谢!

    function pipeRequest(client_req, client_res, method) {
        var options = {
           hostname: HOSTNAME,
           port: PORT,
            path: client_req.url,
            method: method
        };

        var proxy = http.request(options, function (res) {
           res.pipe(client_res, {
              end: true
           });
         });

         if(client_req.url === "/ops/blong/image/upload"){
            console.log(client_req.headers['content-type']);
         }

         client_req.pipe(proxy, {
            end: true
         });
     }

    function onRequest(client_req, client_res) {
          var my_path = url.parse(client_req.url).pathname,
          full_path = path.join(process.cwd(), my_path);

         //Forward API calls
         if (client_req.method === 'POST') {
              pipeRequest(client_req, client_res, 'POST');

              //Return local files for static content
         }  else {
               filesys.exists(full_path, function (exists) {
                 bla bla bla....

0 个答案:

没有答案