c# - API file upload (Server Side) check if there is an actual file before trying to read it -


I have created a web-API 2 post method to upload a physical file on the server. I saw that I still can pass that API without any real file.

So when the server side runs the code on these 2 lines

  var sp = new MultipartFormDataStreamProvider (fileName); Wait for the request. Content Redsmith Impact Assin (SP);   

When the client (not a browser, no fidler) calls the API, but does not upload a file, I get an exception (which gets stuck).

Question : Is there a way to see that the request is made in the file, before calling request Request.Content.ReasAsMultipartAsync ??

My problem is not to trap the exception, but to find a clear path to know before the exception came in, there was no file so that I could inform the calling client about it.

Another approach that you can take (only if you host your service at IIS)>

  HTTPRPSPassword Message Results = Zero; Var httpRequest = HttpContext.Current.Request; // Check that if files are available (httpRequest.Files.Count> 0) {  

Note that you system. You are taking dependency on the web, but if you are on IIS and it is not okay to host yourself.

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -