public static async Task<MultipartFormInfo> ReadFile(this ApiController controller) { var Request = controller.Request; if (Request.Content.IsMimeMultipartContent()) { string root = HttpContext.Current.Server.MapPath("~/App_Data"); var provider = new MultipartFormDataStreamProvider(root); await Request.Content.ReadAsMultipartAsync(provider); var form = new MultipartFormInfo(); foreach (MultipartFileData file in provider.FileData) { var fileName = file.Headers.ContentDisposition.FileName; fileName = fileName.Replace("\"", ""); var mpi = new MultipartFileInfo() { RemoteFileName = fileName, FileInfo = new FileInfo(file.LocalFileName) }; form.Files.Add(mpi); } foreach (var key in provider.FormData.AllKeys) { form.FormData[key] = provider.FormData.GetValues(key); } return form; } return null; }
public static async Task <MultipartFormInfo> ReadFile(this ApiController controller) { var Request = controller.Request; if (Request.Content.IsMimeMultipartContent()) { string root = HttpContext.Current.Server.MapPath("~/App_Data"); var provider = new MultipartFormDataStreamProvider(root); await Request.Content.ReadAsMultipartAsync(provider); var form = new MultipartFormInfo(); foreach (MultipartFileData file in provider.FileData) { var fileName = file.Headers.ContentDisposition.FileName; fileName = fileName.Replace("\"", ""); var mpi = new MultipartFileInfo() { RemoteFileName = fileName, FileInfo = new FileInfo(file.LocalFileName) }; form.Files.Add(mpi); } foreach (var key in provider.FormData.AllKeys) { form.FormData[key] = provider.FormData.GetValues(key); } return(form); } return(null); }
public LocalMultipartFileInfo(MultipartFileInfo fileInfo) { FileName = fileInfo.FileName; Length = fileInfo.Length; Name = fileInfo.Name; }