如何使用node.js将文件从一台服务器传输到另一台服务器
如果有人在别处问我这个问题,我很抱歉,但是我找不到一个合适的方法来解决这个令人烦恼的问题,所以这里是我的情况 我有一个node.js脚本,可以从头创建一个excel文档,一切都正常工作。然而,我在将这个新创建的文件保存到另一个运行ColdFusion的远程服务器上时遇到了问题(不确定这是否重要,但我想我至少应该提到它) 下面的代码从node.js生成一个请求,但是coldfusion一直告诉我没有要解析的文件。我错过了一些基本的东西吗 Node.js 冷饮如何使用node.js将文件从一台服务器传输到另一台服务器,node.js,file-transfer,Node.js,File Transfer,如果有人在别处问我这个问题,我很抱歉,但是我找不到一个合适的方法来解决这个令人烦恼的问题,所以这里是我的情况 我有一个node.js脚本,可以从头创建一个excel文档,一切都正常工作。然而,我在将这个新创建的文件保存到另一个运行ColdFusion的远程服务器上时遇到了问题(不确定这是否重要,但我想我至少应该提到它) 下面的代码从node.js生成一个请求,但是coldfusion一直告诉我没有要解析的文件。我错过了一些基本的东西吗 Node.js 冷饮 不确定,但如果您仍然需要 var e
不确定,但如果您仍然需要
var excel_hook = "http://localhost/models/post_hooks/excel.cfc?method=getReportDataAjax";
var data = {
excelFile: {
// Hard Coding this to see why the post is NOT picking up the file
file: "temp/check_history_test.xlsx",// + file_name,
content_type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
}
};
var requestOptions = {
host: "http://localhost",
path: "/excel.cfc?method=getReportDataAjax",
method: "POST"
};
var request = http.request(requestOptions, function(res){
res.setEncoding('utf8');
res.on('data', function(chunk){
console.log(chunk);
});
res.on('end', function(err, body){
callback(err, body);
});
});
request.on("error", function(err){
console.error("Request Failed:" + err);
});
--
var fileStream = fs.createReadStream("temp/" + file_name);
fileStream.on('data', function(data){
console.log("File Data:");
console.log(data);
request.write(data);
});
fileStream.on('error', function(err){
console.error("File Error:", err);
throw err;
});
fileStream.on('end', function(){
request.end();
});
component extends="models.models"{
/**
Main remote method called by the javascript controller
*/
remote function getReportDataAjax() returnFormat="JSON"{
var reportData = uploadExcel(form.excelFile);
reportData = SerializeJSON(reportData);
return reportData;
}//end
/**
Returns struct containing all data - called by the remote method above
*/
public function uploadExcel(required excelFile)
{
var returnObj = fileUpload("temp", excelFile, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
return {
"bSuccess": true
};
}
}//end component