我有一个快速应用程序,我在其中使用强大的文件上传功能。
我的代码如下所示
form
.on('field', function(field, value){
if (field == 'file_name'){
if(value == 'filename'){
res.send('requestInterrupted');
}
}
})
.on('file', function(field, file){
client.putFile(file.path, file.hash, function(err, response){
console.log(response.statusCode);
})
})
.on('end', function(){
console.log('-> upload done');
res.send('Done');
});
基本上我想要的是,如果假设字段 file_name 的值与某个字符串匹配,那么我想快速响应,因为我不需要完成上传。如果那时文件已经上传,那么也不是问题。但如果文件尚未完全上传,那么我想在那里结束请求。
在我的开发环境中,我无法这样做,因为文件上传得非常快,因为它在同一系统中。我现在无法部署它是一些远程服务器和测试。 因此,如果像我在 form.on('field', function(field, value){...})
函数中所做的那样发送响应会结束请求的进一步传输,请帮助我吗?
最佳答案
尝试res.<strong>end</strong>()
if (field == 'file_name'){
if(value == 'filename'){
res.end('requestInterrupted');
}
}
我没有测试过。
关于node.js - 在 Node.js 中结束请求 Formidable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17711202/