【问题标题】:sending and recieving files through RestBulider通过 Rest Builder 发送和接收文件
【发布时间】:2021-04-16 16:40:36
【问题描述】:
controller on localhost:8000
const fs = require("fs");
exports.install = function () {
  ROUTE("GET     /", indexPage);
};

function indexPage() {
  var self = this;

  console.log(" In GET ROUTE");


  RESTBuilder.GET("http://127.0.0.1:8500/getFile/").stream(function (
    err,
    response
  ) {
    if (err) {
      console.log(err);
      return;
    }
   
    var writer = fs.createWriteStream("./public/testBuilder.txt");
    // console.log("Writing to file");
    response.pipe(writer);
    self.json({ thankyou: "ok" });
  });
}


controller on localhost:8500

exports.install = function () {
  ROUTE("GET /getFile/", test);
};

function test() {
  var self = this;
  console.log("#################");
  console.log(self.body); 
  self.file("~trimSail/restBuilder.txt");
  // });
}

以上代码在 totaljs 3 中有效,但在 total4 中失败。 发送文件以响应 RestBuilder.GET 并将响应流式传输到文件。 错误 response.pipe 不是函数。

【问题讨论】:

    标签: total.js


    【解决方案1】:

    首先,请清理你的代码。

    针对 Total.js 进行了优化

    const Fs = require('fs');
    
    exports.install = function () {
        ROUTE('GET /', index);
    };
    
    function index() {
    
        var $ = this;
    
        console.log('In GET ROUTE');
    
        RESTBuilder.GET('http://127.0.0.1:8500/getFile/').stream($.successful(function(response) { 
            var writer = Fs.createWriteStream('./public/testBuilder.txt');
            response.stream.pipe(writer);
            $.json({ thankyou: 'ok' });
        }));
    
    }
    

    【讨论】:

      猜你喜欢
      • 2016-12-08
      • 2020-12-21
      • 1970-01-01
      • 1970-01-01
      • 2021-09-15
      • 1970-01-01
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多