예제 #1
0
        public ActionResult ImagePreview()
        {
            RequestUtil req = new RequestUtil();

            string callback = req.String("callback");
            int    width    = req.Int("width", defaultValue: 640);
            int    height   = req.Int("height", defaultValue: 1024);

            HttpPostedFileBase pic = Request.Files.Count == 0 ? null : Request.Files[0];

            if (pic != null && pic.ContentLength != 0)
            {
                byte[] imageBuffer = ImageUtil.Compress(pic.InputStream, 40, width, height);

                string guid = System.Guid.NewGuid().ToString("N");

                CacheUtil.CreateCache("preview-" + guid, 0.1, imageBuffer);

                return(Content(HtmlUtil.Result(callback, new { success = true, guid = guid, name = Request.Files.Keys[0] })));
            }
            else
            {
                return(Content(HtmlUtil.Result(callback, new { success = false, msg = "您还未选择图片" })));
            }
        }