I'm using node.js with the express framework and I'm building a form where I can upload files, I'm using node-formidable for this.
My problem is that I can't close the request if I found an error with the uploaded files. I want to check file types, size etc.. So I can get the proper files uploaded, and the files are actually not uploaded so I don't waste time.
So the problem is that I can't stop the HTTP request.
Here is what I have tried so far:
request.connection.destroy();
response.end('something went wrong...');
I assume that the connection.destroy()
aborts the request, and I know this because it fires the formidables form abort event (form.on('abort', function(){ ... })
) But the file is still uploading, and the response doesn't arrives just after the file was uploaded.
So how should I close the HTTP Request, and send a message back to the client?
EDIT:
And something else, when I don't use response.end()
then it works, except that the Client waits for the the answer, it's weird :\
The correct way for doing this is:
request.pause();
response.status = 400;
response.end('something went wrong...');
Source: https://groups.google.com/forum/?fromgroups=#!topic/nodejs/2gIsWPj43lI
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With