前端使用Formidable将文档上载到服务器。处理此问题的控制器如下所示:
DocumentController.js
uploadDocument: function (req, res) {
let params = [];
let jobId, documentRename, documentType, documentPath;
let form = new formidable.IncomingForm();
// store all uploads in the /uploads directory
form.uploadDir = '\\\\backend-server\\E$\\Program Files\\Output\\Batch Holding Area\\';
// every time a file has been uploaded successfully,
// rename it to it's orignal name
form.on('file', function(name, file) {
//rename the incoming file to the file's name
documentPath = form.uploadDir + file.name;
fs.rename(file.path, form.uploadDir + file.name);
});
form.on('field', function (key, field) {
//console.log('Got a field:', field);
//console.log('Got a field name:', name);
params.push([key, field]);
});
// log any errors that occur
form.on('error', function(err) {
return res.serverError(err);
});
// once all the files have been uploaded, send a response to the client
form.on('end', function() {
//*** Does something here with the parameters ***
let jobVars = { 'foo' : 'bar'};
let jobId = "ABCD";
return DocumentService.uploadFileVars(req.session.sessionId, jobId, jobVars).then(function (response) {
return res.send("Document uploaded.");
}).catch(function (err) {
return res.serverError(err);
});
});
form.parse(req);
}
如您所见,它尝试将文件上传到服务器上的特定目标,然后使用参数并执行一些其他功能。
我可以在我的开发环境中运行此应用程序。此功能按预期工作,并将文件存储在服务器上,并完成其余功能。将其部署到Ubuntu机器时会发生问题。它运行时会引发未处理的错误,该错误会杀死帆。浏览器中的响应仅为net::ERROR_CONNECTION_RESET
。
这有点超出我的技能范围,因此我不确定如何调试此问题。我怀疑这里的问题与文件路径的格式有关,但我也认为这可能是CORS问题,但是从本地计算机上可以解决此问题吗?