Web API: ActionFilter that executes before entire request is received

253 Views Asked by At

I'm building a web service in Web API, and one of the actions receives very large files. They're video files, typically between 100-200mb. This means that the upload times will be long.

I have already written a Type Formatter so that my controller action can use the video file (well...the file information anyway, which is written to disk by the Type Formatter), however in my action method, I then check whether the URL arguments that the user has submitted are valid, and throw an exception if not.

This seems very inefficient, because I can tell whether the user is submitting the correct URL arguments as soon as the HTTP request headers are submitted - is it really necessary to wait another 20-30 minutes for the body to come through before sending a simple 404 response back?

Ideally, I'm looking to create (or use an existing one) a FilterAttribute that executes just after the HTTP request headers are received, but before the HTTP request body is submitted. I think this is possible, because I think AuthorizeAttribute would want to do the same thing, but I'm not sure how to accomplish it. My main difficulty is that I'd also need access to the values of the action's arguments (two of which are in the URL, the other is obviously posted in the HTTP request body).

Any ideas?

0

There are 0 best solutions below