【发布时间】:2020-05-07 20:13:35
【问题描述】:
这是我的代码,我在其中获取上传视频并在扩展不是 mp4 时检查它的扩展我想返回 else 语句并从服务器传递错误但是当我收到此错误并且当我是 console.log 时此错误会打印服务器没有响应 505 错误,当扩展为 mp4 时它工作正常。
const videoStorage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, config.videoStorage);
},
filename: function (req, videoFile, cb) {
if (path.extension(videoFile.originalname) !== '.mp4') {
const name = `${videoFile
.fieldname}-${Date
.now()}_${
videoFile.originalname}`;
return cb(null, name.replace(/\s/g, ""));
} else {
return cb(new Error("sorry"));
}
}
});
MediaService
.uploadVideo(formData, this.getUploadProgress)
.then(data => {
let order = {
...this.state.project
};
if (!order.project) {
order = {
project: {
mediaId: data
}
};
}
order.project.mediaId = data;
console.log("videoid added ===", order);
this.setState({uploading: false, videoId: data, isValid: true, project: order});
message.success("Video uploaded successfully");
})
.catch(error => {
message.error(error);
this.setState({message: error, uploading: false});
});
};
【问题讨论】:
标签: node.js reactjs server promise react-redux