I have a web api endpoint which accepts some files as content body. In the endpoint I am checking the content size, and if it exceeds the 10MB file size, I am rejecting the request. For other endpoint we need to accept different file size limits. So, it is certain that I can't just change the web config to accept a single max file size limit.
I am using the following code to get the content's size and do the logic checking.
long? contentLength = this.Request.Content.Headers.ContentLength;
The problem is, I don't want to wait in the method to load all of the uploaded file to receive. When I send files from swagger, I have to wait the files to be uploaded and then the method starts executing. Example: suppose my bandwidth is 3mbps and I am uploading a 10MB file. So, it is taking (80mb/3 =) 26sec approx. before my above code starts executed.
What needs to be changed , or , is it possible actually, that I can detect the content length without uploading the whole content to the server?