using ExportMap.cs; using ExportMap.Models; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Net.Http; using System.Threading.Tasks; using System.Web.Http; namespace ExportMap.Controllers { public class UploadController : ApiController { [HttpPost] public Task> Post([FromUri]string path) { //string root = HttpContext.Current.Server.MapPath("~/uploads"); if (string.IsNullOrEmpty(path)) return null; string root = Path.Combine(Tools.GetSetting("tempFolder"), path); if (!Directory.Exists(root)) Directory.CreateDirectory(root); if (!Request.Content.IsMimeMultipartContent()) { throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotAcceptable, "请求的格式不正确!")); } var provider = new CustomMultipartFormDataStreamProvider(root); var task = Request.Content.ReadAsMultipartAsync(provider).ContinueWith>(t => { if (t.IsFaulted || t.IsCanceled) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } var fileInfos = provider.FileData.Select(i => { FileInfo info = new FileInfo(i.LocalFileName); return new FileDesc(info.Name, info.Length); }); return fileInfos; }); return task; } } }