我有一个API,可将图像转换为gcode文件,以及将文件存储和移动到适当的目录。
如果图像尺寸较大,则该过程可能会花费大量时间(有时会超过3m),如果是大图像,则在调用API并完成操作后,我得到 net的信息: :虽然我没有在端点代码中发送任何空响应,并且超时是axios的默认值(= 0),但我的axios.post()调用中却是:ERR_EMPTY_RESPONSE 。
express或axios是否缺少配置?
我是否缺少有关API的内容?
帮助!
注意:
所有操作均在端点中成功执行,仅响应发送为空!
router.post('/convert', upload.single('image'), (req, res) => {
//? req.file {fieldname, originalname, encoding, mimetype, buffer}
const fileObject = req.file;
let results = null;
const params = req.body.parameters;
filesHandler.moveImage(fileObject.path, fileObject.filename)
.then((newPath) => {
controller.defaultImageConversion(newPath, params)
.then((data) => {
results = data;
//? filename ex 2019-02-24T16:25:36.772Z.gcode
const splitted = fileObject.filename.split(".");
//? splitted[0] + "." + splitted[1] => 2019-02-24T16:25:36 + 772Z
const fileName = splitted[0] + "." + splitted[1] + ".gcode";
filesHandler.moveDotGcode(data.dirgcode, fileName)
.then((result) => {
const tt = new Date(Date.now());
const endTime = `${tt.getHours()}:${tt.getMinutes()}:${tt.getSeconds()}`;
const {
toolDiameter,
sensitivity,
scaleAxes,
deepStep,
whiteZ,
blackZ,
safeZ,
feedrate,
errBlackPixel,
time,
imgSize
} = results.config;
const t = new Date(time);
const startTime = `${t.getHours()}:${t.getMinutes()}:${t.getSeconds()}`;
controller.storeConversionDetails({
image: fileObject.filename,
gcode: fileName,
toolDiameter,
sensitivity,
scaleAxes,
deepStep,
whiteZ,
blackZ,
safeZ,
feedrate,
time,
errBlackPixel,
imgSize
}).then((result) => {
filesHandler.getGCodeFileStats(fileName)
.then((result) => {
let size = result.size;
// console.log();
res.send({
success: "Operation Completed Successfully, Image Conversion is Done",
data: {
toolDiameter,
sensitivity,
scaleAxes,
deepStep,
whiteZ,
blackZ,
safeZ,
feedrate,
errBlackPixel,
imgSize,
startTime,
endTime,
elapsedTime: (tt - t) * 0.001,
fileName: fileName,
size: size
}
});
}).catch((error) => {
console.log(error);
res.status(500).send({
failure: "Internal error occurred while getting file stats",
error
});
});
}).catch((error) => {
console.log(error);
res.status(500).send({
failure: "Internal error occurred while storing data into Database",
error
});
});
}).catch((error) => {
res.status(500).send({
failure: "Internal error occurred while moving gcode to directory",
error
});
});
}).catch((error) => {
res.status(500).send({
failure: "Internal error occurred while converting image, try again",
error
});
});
}).catch((error) => {
res.status(500).send({
failure: "Internal error occurred, try again",
error
});
});
});