public async Task <FileResult> Post() { //Check whether it is an HTML form file upload request if (!Request.Content.IsMimeMultipartContent("form-data")) { //return UnsupportedMediaType response back if not throw new HttpResponseException( new HttpResponseMessage( HttpStatusCode.UnsupportedMediaType) ); } //Determine the upload path var uploadPath = HttpContext.Current.Server.MapPath("~/Files"); var multipartFormDataStreamProvider = new CustomMultipartFormDataStreamProvider(uploadPath); // Read the MIME multipart asynchronously // content using the stream provider we just created. await Request.Content.ReadAsMultipartAsync( multipartFormDataStreamProvider); // Create response return(new FileResult { FileNames = multipartFormDataStreamProvider .FileData.Select( entry => entry.LocalFileName), Submitter = multipartFormDataStreamProvider .FormData["submitter"] }); }
public async Task<FileResult> Post() { //Check whether it is an HTML form file upload request if (!Request.Content.IsMimeMultipartContent("form-data")) { //return UnsupportedMediaType response back if not throw new HttpResponseException( new HttpResponseMessage( HttpStatusCode.UnsupportedMediaType) ); } //Determine the upload path var uploadPath = HttpContext.Current.Server.MapPath("~/Files"); var multipartFormDataStreamProvider = new CustomMultipartFormDataStreamProvider(uploadPath); // Read the MIME multipart asynchronously // content using the stream provider we just created. await Request.Content.ReadAsMultipartAsync( multipartFormDataStreamProvider); // Create response return new FileResult { FileNames = multipartFormDataStreamProvider .FileData.Select( entry => entry.LocalFileName), Submitter = multipartFormDataStreamProvider .FormData["submitter"] }; }