node.js - 如何在 NodeJS(Express js)中检测中止的 ajax 请求
问题描述
我有一个上传文件的上传功能。还有一个中止功能可以中止请求。
upload(){
this.req = $.ajax(SetupService.baseUrl + '/upload/audio', {
xhr: () => {
const xhr = new XMLHttpRequest()
return xhr;
},
processData: false,
contentType: false,
data: formdata
});
}
abort() {
this.req.abort();
}
在服务端,我使用带有 express 和 multer 的 nodej 进行文件处理。文件上传成功,但如果我单击中止按钮,服务器不知道。如何从 express js 服务器检查请求是否中止
router.post('/audio', function (req, res) {
console.log('uploading');
// How to check if the req is aborted by client or not
});