I am having an express app where I am using formidable for file upload.
My code looks like this
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');
});
Basically what I want is if suppose the value of field file_name matches some string then I want to respond quickly as I dont need the upload to be completed. And if by that time the file has been uploaded then also its not a problem. But if the file is yet to be uploaded completely then I want to end the request there itself.
In my development env I am not able to do so as the file is uploaded very fast as its in the same system. I can't deploy it now is some remote server and test. So please just help me out if sending response like I have done in form.on('field', function(field, value){...}) function end the request from being carried further?
Try res.end()
if (field == 'file_name'){
if(value == 'filename'){
res.end('requestInterrupted');
}
}
I haven't tested.