Sourav Kumar Das

Sourav Kumar Das

  • 519
  • 2.5k
  • 173.1k

How to use Multipart/formdata in Web API?

Jan 13 2020 3:37 AM
Hi All,
 
I have a doubt in the below code that I have tried the multi part/ form data in Web Config and Global.asax files and passed through controller but I am not getting the multipart data.
 
So is this the right way or there is an another way to pass the multi part / form data.
 
//Web Config.cs File
  1. config.Formatters.XmlFormatter.SupportedMediaTypes.Add(new System.Net.Http.Headers.MediaTypeHeaderValue("multipart/form-data"));  
//Global.Asax File
  1. GlobalConfiguration.Configuration.Formatters.Add(new FormMultipartEncodedMediaTypeFormatter());  
// Controller File
  1. var EmailId = HttpContext.Current.Request.Params["EmailId"];  
  2. var MobileNo = HttpContext.Current.Request.Params["MobileNo"];  
  3. var UserName = HttpContext.Current.Request.Params["UserName"];  
  4. var Password = HttpContext.Current.Request.Params["Password"];  
  5. var Address = HttpContext.Current.Request.Params["Address"];  
  6. var IDProof = HttpContext.Current.Request.Params["IDProof"];  
  7. var VendorPhoto = HttpContext.Current.Request.Files["VendorPhoto"];  
If there's a solution please let me know it as soon as possible.

Answers (1)