Example #1
0
        public ActionResult UploadifyFile(UploadifyModel @params)
        {
            try
            {
                Response.ContentType = "text/plain";
                Response.Charset = "UTF-8";
                HttpFileCollectionBase filecollection = Request.Files;
                HttpPostedFileBase postedfile = filecollection.Get("filedata");

                if (postedfile == null) { return Content(new { Url = "", ThumbnailUrl = "" }.ToJson()); }

                string dirName = _configService.GetByKey<string>("UploadFileDir", "Files");
                string savePath = saveRootPath + "/" + dirName + "/" + DateTime.Now.Year + "/" + DateTime.Now.Month;
                if (!Directory.Exists(root + "/" + savePath)) Directory.CreateDirectory(root + "/" + savePath);
                string saveName = Guid.NewGuid().ToString();
                string ext = postedfile.FileName.GetExtension();
                string fullFileName = saveName + ext;
                string fullFileSavePath = savePath + "/" + fullFileName;
                postedfile.SaveAs(root + "/" + fullFileSavePath);

                var result = new
                {
                    Url = @params.UploadPath + "/" + fullFileSavePath
                };

                return Content(result.ToJson());
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }
            return Content("{Url:\"\"}");
        }
Example #2
0
        public ActionResult UploadifyImage(UploadifyModel @params)
        {
            try
            {
                Response.ContentType = "text/plain";
                Response.Charset = "UTF-8";
                HttpFileCollectionBase filecollection = Request.Files;
                HttpPostedFileBase postedfile = filecollection.Get("filedata");

                if (postedfile == null) { return Content(new { Url = "", ThumbnailUrl = "" }.ToJson()); }

                int compressionRatio = 90;

                string dirName = _configService.GetByKey<string>("UploadImageDir", "Images");
                string savePath = saveRootPath + "/" + dirName + "/" + DateTime.Now.Year + "/" + DateTime.Now.Month;
                if (!Directory.Exists(root + "/" + savePath)) Directory.CreateDirectory(root + "/" + savePath);
                string saveName = Guid.NewGuid() + "_0";
                string ext = postedfile.FileName.GetExtension();
                string fullFileName = saveName + ext;
                string fullFileSavePath = savePath + "/" + fullFileName;
                postedfile.SaveAs(root + "/" + fullFileSavePath);

                if (@params.CreateRule.HasValue())
                {
                    if (!"0,0".Equals(@params.CreateRule))
                    {
                        var createRuleArray = @params.CreateRule.Split('|');
                        var index = 0;
                        foreach (var item in createRuleArray)
                        {
                            index++;
                            var ruleDetailArray = item.Split(',');
                            if (ruleDetailArray.Length > 1)
                            {
                                var maxLength = ruleDetailArray[0].ToInt(150);
                                var createType = "Cut";
                                switch (ruleDetailArray[1])
                                {
                                    case "0":
                                        createType = "DB";
                                        break;
                                    case "1":
                                        createType = "W";
                                        break;
                                    case "2":
                                        createType = "H";
                                        break;
                                    default:
                                        break;
                                }

                                var fullThumbnailSavePath = savePath + "/" + saveName.Replace("_0", "_" + index) + ext;
                                ImageHelper.MakeThumbnail(root + "/" + fullFileSavePath, root + "/" + fullThumbnailSavePath, maxLength, maxLength, createType, compressionRatio);
                            }
                        }

                        var isSaveOriginalImage = _configService.GetByKey<bool>("UploadIsSaveOriginalImage", true);
                        if (!isSaveOriginalImage)
                        {
                            System.IO.File.Delete(root + "/" + fullFileSavePath);
                        }
                    }
                }

                var result = new
                {
                    Url = @params.UploadPath + "/" + fullFileSavePath
                };

                return Content(result.ToJson());
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }
            return Content("{Url:\"\"}");
        }
Example #3
0
 public ActionResult Uploadify(UploadifyModel @params)
 {
     return View(@params);
 }