Case 1

Let's see the code shown in the following:

  1. string rootPath = ConfigurationManager.AppSettings["FilePath"];
  2. var currentApplicationPath = HttpContext.Current.Request.PhysicalApplicationPath;
  3. var provider = new MultipartFormDataStreamProvider(currentApplicationPath + "\\tempUploads");
  4. try{
  5. await Request.Content.ReadAsMultipartAsync(provider);
  6. }
  7. catch(Exception ex)
  8. {
  9. throw ex;
  10. }

Here i am passing from header Accept: tex/json.

I am getting error. with used above code, error shown in the following screenshot:

Case 2

If I used MultipartFormDataStreamProvider with app ConfigurationManager.AppSettings["FilePath"] than I was successfully execute my code.

  1. string rootPath = ConfigurationManager.AppSettings["FilePath"];
  2. var provider = new MultipartFormDataStreamProvider(ConfigurationManager.AppSettings["FilePath"])
  3. try{
  4. await Request.Content.ReadAsMultipartAsync(provider);
  5. }
  6. catch(Exception ex)
  7. {
  8. throw ex;
  9. }