2

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?

Foyzul Karim
  • 4,252
  • 5
  • 47
  • 70
  • If you are not interested in checking the content, you should be able to control the max Request length just by configuring the `maxRequestLength`. See [How to increase the max upload file size in ASP.NET](https://stackoverflow.com/q/288612/205233) and similar questions. – Filburt Jun 09 '17 at 08:48
  • I can not just change the web config file, because the server accepts different file size for different purpose. Please let me know if I am not clear about my explanation. – Foyzul Karim Jun 09 '17 at 08:55
  • 1
    You should be able to configure this on a per-endpoint basis. Please mention constraints like this - it is not clear from your question that you need to consider different max values. – Filburt Jun 09 '17 at 09:04
  • modified the question. but do you have any suggestion / idea about my particular problem? – Foyzul Karim Jun 09 '17 at 09:09
  • I would expect [this answer to "MVC3 Action File Size Limit"](https://stackoverflow.com/a/10834379/205233) should be a possible solution. – Filburt Jun 09 '17 at 09:28

0 Answers0