Question: What I have:
------------

I'm using [node.js](http://nodejs.org/) with the [express framework](https://github.com/visionmedia/express) and I'm building a form where I can upload files, I'm using [node-formidable](https://github.com/felixge/node-formidable) for this.

What's the problem
------------------

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.

What I have tried
-----------------

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 :\

Answer: 
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>
Try with following code:

1. When your server side validation fails, give a response like:

`res.json({'IsFileUploaded':'false', 'requiredFileSize': '1000bytes', 'actualFileSize': '800bytes', 'AlertMsg':'File size should be at least 1000 bytes....'})` 

It closes connection as well as you can pass your data in JSON format