UploadFileController.cs
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; namespace YFAPICommon.Controllers { public class FileBase64Input { public string base64 { set; get; } } public class UploadFileOutput { public string url { set; get; } public int error { set; get; } public string msg { set; get; } } public class UploadFileOutputCkeditor { public string url { set; get; } public int uploaded { set; get; } } /// <summary> /// 文件上传 /// </summary> public class UploadFileController : ApiController { private static string serverPath = System.Configuration.ConfigurationSettings.AppSettings["serverPath"]; private static string localPath = System.Configuration.ConfigurationSettings.AppSettings["localPath"]; [HttpPost] public UploadFileOutput UploadWithStream() { System.Web.HttpContext context = System.Web.HttpContext.Current; UploadFileOutput returnNode = new UploadFileOutput(); string date = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString(); int cout = context.Request.Files.Count; if (cout > 0) { System.Web.HttpPostedFile hpf = context.Request.Files[0]; if (hpf != null) { string fileExt = Path.GetExtension(hpf.FileName).ToLower(); //只能上传文件,过滤不可上传的文件类型 string fileFilt = ".gif|.jpg|.bmp|.jpeg|.png";