如果在别处问过这个问题我很抱歉,但我找不到合适的解决方案来解决这个棘手的问题,所以这就是我的情况.
我有一个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