I am programming an input file with angularJS and c # MVC. At the time of reviewing the folder where you keep the files shows them to me in the following way
So I have my code on the controller
public class SubirHvController : ApiController
{
[System.Web.Http.HttpPost]
[System.Web.Http.Route("PostFileWithData")]
public async Task<HttpResponseMessage> Post()
{
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
var root = HttpContext.Current.Server.MapPath("~/App_Data/Uploadfiles");
Directory.CreateDirectory(root);
var provider = new MultipartFormDataStreamProvider(root);
var result = await Request.Content.ReadAsMultipartAsync(provider);
var model = result.FormData["jsonData"];
if (model == null)
{
throw new HttpResponseException(HttpStatusCode.BadRequest);
}
//TODO: Do something with the JSON data.
//get the posted files
foreach (var file in result.FileData)
{
//TODO: Do something with uploaded file.
}
return Request.CreateResponse(HttpStatusCode.OK, "success!");
}
}
It seems that if the data is arriving well
Any opinion would be very helpful. Thanks