javascript - 如何将文件从一台服务器下载到另一台服务器
问题描述
我正在尝试将文件从一台服务器下载到另一台服务器,例如假设我有 2 个服务器 1.api 服务器和 2.test 服务器
在测试服务器
downloadFile(req, res) {
let file = path.join(__dirname, "../config/config.js");
res.status(200).send("http://ip-address:port" + file);
}
在 api 服务器中
const http = require('http');
const path = require('path');
HttpDownload(req,res) {
let file = fs_file.createWriteStream(path.join(__dirname, "..", "..", "temp", "output.js"));
http.get(url-to-test-server, function (response) {
response.on('data', function (chunk) {
file.write(chunk)
})
response.on('end', function () {
console.log('download file completed.')
res.download(path.join(__dirname, "..", "..", "temp", "output.js"))
})
})
}
谁能建议我我做错了什么?预先感谢。
解决方案
推荐阅读
- android - 如何添加计时器以获取 GPS 位置?
- javascript - 为什么我的 onClick 事件没有在 React 上触发?
- ember.js - Emberjs:如何在“npm install”之后导入
- mysql - 创建表时出现此错误 #1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册
- r - 你如何强制 Rmarkdown 图是方形而不是矩形?
- carousel - 反应引导 Carousel.js
- mysql - 使用codeigniter开发相册,查询选择图片?
- html - 如何让wordpress显示和单个网页显示一样的效果?
- c# - VS2017 社区中 .editorconfig 文件的问题
- webpack - 将用于浏览器服务的单个 AWS SDK JS 与 webpack 和 Typescript 集成