total.js - 通过 RestBulider 发送和接收文件
问题描述
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 进行了优化:
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' });
}));
}
推荐阅读
- r - 在 rbind() 中将单元格值解析为行名
- vb.net - 调整多个图像的大小并将它们保存到单独的文件夹中
- java - XML反序列化后访问子列表抛出ConcurrentModificationException
- python - 在 Python 3 中,如何在排行榜中查找排名并将其转换为字典?
- google-app-engine - 子域通过 DNS 解析到不同的网站
- python - pip install numpy - 不在 ec2 上安装 numpy
- python - Ansible:无法设置 vars 变量
- angular - 在描述调用中获取夹具和组件值 - Angular 单元测试
- fullcalendar - Fullcalendar:更改 startParam / endParam 键的名称
- python - 为什么 os.linesep 仅适用于 Python 中的某些字符串?