nitin somal

nitin somal

  • NA
  • 38
  • 9.4k

Upload file with model in Asp.net web api using fiddler

Jan 6 2020 9:30 AM
I have the following Web API end point:
 
[System.Web.Http.HttpPost]
public AddEvidenceResponseModel UploadCameraDetail(ABC1 model1){
string fileSaveLocation = HttpContext.Current.Server.MapPath("~/Evidence"); CustomMultipartFormDataStreamProvider provider = new CustomMultipartFormDataStreamProvider(fileSaveLocation); List files = new List(); Request.Content.ReadAsMultipartAsync(provider);
foreach (MultipartFileData file in provider.FileData) { files.Add(Path.GetFileName(file.LocalFileName));
}
}
 
In which I am uploading the txt file with model1 parameter. To hit this web api endpoint I am using fiddler with the following
 
Request Header: Content-Type: application/json,multipart/form-data,text/plain; boundary=-------------------------acebdf13572468 Host: localhost:53760 Content-Length: 360
 
Request Body: ---------------------------acebdf13572468 Content-Disposition: form-data; name="model1" Content-Type: application/json,multipart/form-data
{"MyProperty1":"tt"} ---------------------------acebdf13572468 Content-Disposition: form-data; name="fieldNameHere"; filename="A.txt" Content-Type: text/plain
 
<@INCLUDE C:\Users\Nitin.Singh\Desktop\Images\A.txt@> ---------------------------acebdf13572468--
 
Problem: I am not able to get the value of model1 parameter and txt file value inside the web api end point method 

Answers (1)