1 //独立部署的图片服务器
2 public ActionResult Index()
3 {
4 //if (Request.HttpMethod == "OPTION")
5 //{
6 // Response.AddHeader("Access-Control-Allow-Methods", "GET,POST");
7 // Response.AddHeader("Access-Control-Allow-Headers", "Content-Type,Accept");
8 // Response.AddHeader("Access-Control-Max-Age", "1728000");
9 // Response.AddHeader("Access-Control-Allow-Origin", "*");
10 //}
11 string openId = Request["openId"];
12 HttpPostedFileBase httpPostedFileBase = Request.Files["Filedata"];
13 string fileName = httpPostedFileBase.FileName;
14 string extensionName = System.IO.Path.GetExtension(fileName).ToLower();
15 if (extensionName == ".jpg" || extensionName == ".jpeg")
16 {
17 string virtualPath = "/uploads" + "/" + fileName.Replace(extensionName, "") + DateTime.Now.ToString("yyyyMMddhhmmss") + extensionName;
18 string fullPath = Server.MapPath(virtualPath);
19 httpPostedFileBase.SaveAs(fullPath);
20
21 string savePath = Server.MapPath("/thumbnails" + "/" + openId);
22 string thumbnailFileName = Thumbnail.GetThumbnailImage(160, 120, fullPath, savePath, System.Drawing.Imaging.ImageFormat.Jpeg);
23 //删除原始文件
24 //System.IO.File.Delete(fullPath);
25 NowModel model = new NowModel();
26 model.Id = 0;
27 model.OpenId = openId;
28 model.FileName = thumbnailFileName;
29 nowBLL.Insert(model);
30 return Json(new { res = true, msg = "上传成功!", fileName = thumbnailFileName });
31 }
32 return Json(new { res = false, msg = "上传失败!" });
33 }