如何使用node.js将文件从一个服务器传输到另一个服务器

 懂我的何必解释 发布于 2022-12-28 10:33

如果在别处问过这个问题我很抱歉,但我找不到合适的解决方案来解决这个棘手的问题,所以这就是我的情况.

我有一个node.js脚本,它从头开始创建一个excel文档,一切都按预期工作.但是,我在将这个新创建的文件保存到运行ColdFusion的另一个远程服务器时遇到了问题(不确定这是否重要,但我想我至少会提到它).

以下代码从node.js生成请求,但coldfusion一直告诉我没有要解析的文件.我错过了什么基本的东西?

Node.js的

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();
});

ColdFusion的

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

撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有