public ActionResult File(string config, string pathid, string fileid, string size, string ext)
        {
            FilePathResult res = null;

            try
            {
                int    _intPath = pathid.Value <int>();
                string _pth     = FileManagementUtil.GetFullPath(config, FilePathScheme.Physical, _intPath, fileid, ext);
                string _pyth    = new Uri(_pth).LocalPath;

                if (!size.IsEmpty())
                {
                    _pyth = FileUtil.ChangeFileNameAddSize(_pyth, size);
                }

                bool hasFile = System.IO.File.Exists(_pyth);
                if (hasFile)
                {
                    res = new FilePathResult(_pyth, "image");
                }
                else
                {
                    string _str = Path.Combine(AtawAppContext.Current.MapPath, "Content\\default.jpg");
                    res = new FilePathResult(_str, "image");
                }
            }
            catch
            {
                // AtawAppContext.Current.WebRootPath
                string _str = Path.Combine(AtawAppContext.Current.MapPath, "Content\\default.jpg");
                res = new FilePathResult(_str, "image");
            }
            return(res);
        }
Beispiel #2
0
        public static string GetLoginUserLogoHttpPath(string userId)
        {
            //int _rootId = FileManagementUtil.GetRootID("CoreUserlogo");
            //string _pyPathRoot = FileManagementUtil.GetRootPath(_rootId, FilePathScheme.Physical);
            //FileManagementUtil.g
            string _path = FileManagementUtil.GetFullPath("CoreUserlogo", FilePathScheme.Http, 0, userId, "");

            //_path = new Uri(_path).LocalPath;
            //_path = "http:////{0}".AkFormat(_path.Replace(@"\", "/"));
            _path = FileUtil.ChangeFileNameAddSize(_path, "60-60");
            return(_path.Replace("\\", "/").Replace("http:/", "http://"));
        }
        private ResourceInfo SaveFileByStorageName(HttpPostedFileBase file, string fileStorageName)
        {
            ResourceInfo info = new ResourceInfo();

            string fileExtension = Path.GetExtension(file.FileName);

            if (fileStorageName.IsEmpty() || fileStorageName.ToUpper(ObjectUtil.SysCulture) == "NULL")
            {
                fileStorageName = "Temp";
            }
            string fileID   = AtawAppContext.Current.UnitOfData.GetUniId();
            int    pathID   = fileID.GuidSafeSub();
            string fullPath = FileManagementUtil.GetFullPath(fileStorageName, FilePathScheme.Physical, pathID, fileID, fileExtension);

            fullPath = new Uri(fullPath).LocalPath;
            FileManagementUtil.ForeDirectories(FileManagementUtil.GetParentDirectory(fullPath));
            file.SaveAs(fullPath);

            //判断是否可以转换
            bool isCan = FileManagementUtil.CanDocumentView(fileExtension);

            if (isCan)
            {
                //放到图片预览区
                string fileName = Path.GetFileName(fullPath);
                string _dvPath  = Path.Combine(AtawAppContext.Current.XmlPath, AtawAppContext.Current.DocViewerXml.DocViewerPath, "~Cache_Document", fileName);
                if (!System.IO.File.Exists(_dvPath))
                {
                    //FileUtil.VerifySaveFile(
                    string path = Path.GetDirectoryName(_dvPath);
                    // ConfirmPath(path);
                    FileUtil.ConfirmPath(path);
                    file.SaveAs(_dvPath);
                }
            }
            string _httpPath = FileManagementUtil.GetFullPath(fileStorageName, FilePathScheme.Http, pathID, fileID, fileExtension);

            info.CanDocumentView   = isCan;
            info.StorageConfigName = fileStorageName;
            info.ExtName           = fileExtension;
            info.FileId            = fileID;
            info.DocumentViewId    = fileID + fileExtension;
            info.FileNameTitle     = Path.GetFileNameWithoutExtension(file.FileName);
            info.FileSizeK         = file.ContentLength / 1024;
            info.InfoType          = ResourceInfoType.Config;
            info.PathID            = pathID;
            info.HttpPath          = _httpPath;
            info.PhysicalPath      = fullPath;

            return(info);
        }
        //上传控件 包括图片和文件
        public string UploadFileAndImage(string fileStorageName, string uploadName, string width = "100", string height = "100", bool isCut = false)
        {
            //保存临时文件
            HttpPostedFileBase file = Request.Files[0];
            ResourceInfo       info = SaveFileByStorageName(file, fileStorageName);

            if (file.ContentType == "image/jpeg")
            {
                //上传图片
                info.IsImage = true;
                if (!isCut)
                {
                    string oldPath  = info.PhysicalPath;
                    string fileName = Path.GetFileName(oldPath);
                    string oldTitle = Path.GetFileNameWithoutExtension(oldPath);

                    if (uploadName.IsEmpty())
                    {
                        if (!height.IsEmpty() && !width.IsEmpty())
                        {
                            string newFile = FileUtil.ChangeFileName(oldPath, ImageCut.GetNewFileTitle(oldTitle, width.Value <int>(), height.Value <int>()));
                            ImageUtil.SavePictureInFile(oldPath, fileName, width.Value <int>(), height.Value <int>(), newFile);
                            string _ff = "{0}-{1}".AkFormat(width, height);
                            info.ExtendList.Add(_ff, _ff);
                        }
                    }
                    else
                    {
                        var _cuts = FileManagementUtil.GetImageCutsByUploadName(uploadName);
                        foreach (ImageCut cut in _cuts)
                        {
                            string newFile = FileUtil.ChangeFileName(oldPath, cut.GetNewFileTitle(oldTitle));
                            ImageUtil.SavePictureInFile(oldPath, fileName, cut.ImageSizeWidth, cut.ImageSizeHeight, newFile, cut.Quality);
                            string _ff = "{0}-{1}".AkFormat(cut.ImageSizeWidth, cut.ImageSizeHeight);
                            info.ExtendList.Add(_ff, _ff);
                        }
                    }
                }
            }
            else
            {
                //上传文件
                info.IsImage = false;
            }

            return(ReturnJson(info));
        }
        /// <summary>
        /// 菜鸟前台上传图片需要的方法,返回格式化json
        /// </summary>
        /// <param name="file"></param>
        /// <param name="fileStorageName"></param>
        ///  <param name="uploadName"></param>
        /// <returns></returns>
        public string UploadWebFile(HttpPostedFileBase file, string fileStorageName, string uploadName)
        {
            var    info     = SaveFileByStorageName(file, fileStorageName);
            string oldPath  = info.PhysicalPath;
            string fileName = Path.GetFileName(oldPath);
            string oldTitle = Path.GetFileNameWithoutExtension(oldPath);

            if (!uploadName.IsEmpty())
            {
                var _cuts = FileManagementUtil.GetImageCutsByUploadName(uploadName);
                foreach (ImageCut cut in _cuts)
                {
                    string newFile = FileUtil.ChangeFileName(oldPath, cut.GetNewFileTitle(oldTitle));
                    ImageUtil.SavePictureInFile(oldPath, fileName, cut.ImageSizeWidth, cut.ImageSizeHeight, newFile, cut.Quality);
                    string _ff = "{0}-{1}".AkFormat(cut.ImageSizeWidth, cut.ImageSizeHeight);
                    info.ExtendList.Add(_ff, _ff);
                }
            }
            return(FastJson(info));
        }
        /// <summary>
        /// 原始图片路径
        /// </summary>
        /// <param name="imgUrl">原始图片路径</param>
        /// <param name="h">裁剪的高度</param>
        /// <param name="w">裁剪的宽度</param>
        /// <param name="x">x坐标</param>
        /// <param name="y">y坐标</param>
        /// <param name="picWidth"></param>
        /// <param name="picHeight"></param>
        /// <returns></returns>
        public string CutImageJcrop(string imgUrl, int h, int w, int x, int y, int picWidth, int picHeight, int newWidth, int newHeight, string fileStorageName, string ResourceInfoList, string UploaderName)
        {
            ResourceInfo info = null;

            if (!ResourceInfoList.IsEmpty())
            {
                List <ResourceInfo> _res = FastToObject <List <ResourceInfo> >(ResourceInfoList);
                info = _res[0];
            }
            string oldTitle = Path.GetFileNameWithoutExtension(info.PhysicalPath);
            string _title   = "{0}-{1}".AkFormat(newWidth, newHeight);
            string _newPath = FileUtil.ChangeFileName(info.PhysicalPath, "{0}_{1}".AkFormat(oldTitle, _title));

            //判断传进来的值是否等于0,如果等于0则直接取截图的大小
            if (newWidth == 0 || newHeight == 0)
            {
                newWidth  = w;
                newHeight = h;
            }
            CutImageForCustom(info.PhysicalPath, _newPath, w, h, x, y, picWidth, picHeight, newWidth, newHeight);
            info.ExtendList.Add(_title, _title);
            string _cropPath = _newPath;

            if (!UploaderName.IsEmpty())
            {
                var _cuts = FileManagementUtil.GetImageCutsByUploadName(UploaderName);
                foreach (ImageCut cut in _cuts)
                {
                    if (cut.ImageSizeWidth != newWidth && cut.ImageSizeHeight != newHeight)
                    {
                        string newFile = FileUtil.ChangeFileName(_cropPath, cut.GetNewFileTitle(oldTitle));
                        ImageUtil.SavePictureInFile(_cropPath, Path.GetFileName(_cropPath), cut.ImageSizeWidth, cut.ImageSizeHeight, newFile, cut.Quality);
                        string _ff = "{0}-{1}".AkFormat(cut.ImageSizeWidth, cut.ImageSizeHeight);
                        info.ExtendList.Add(_ff, _ff);
                    }
                }
            }

            return(ReturnJson(info));
            // return tick;
        }
        public string UploadImage(string fileStorageName, string width, string height, bool isCut, string uploadName)
        {
            //保存临时文件
            HttpPostedFileBase file = Request.Files[0];

            ResourceInfo info = SaveFileByStorageName(file, fileStorageName);

            if (!isCut)
            {
                string oldPath  = info.PhysicalPath;
                string fileName = Path.GetFileName(oldPath);
                string oldTitle = Path.GetFileNameWithoutExtension(oldPath);

                if (uploadName.IsEmpty())
                {
                    if (!height.IsEmpty() && !width.IsEmpty())
                    {
                        string newFile = FileUtil.ChangeFileName(oldPath, ImageCut.GetNewFileTitle(oldTitle, width.Value <int>(), height.Value <int>()));
                        ImageUtil.SavePictureInFile(oldPath, fileName, width.Value <int>(), height.Value <int>(), newFile);
                        string _ff = "{0}-{1}".AkFormat(width, height);
                        info.ExtendList.Add(_ff, _ff);
                    }
                }
                else
                {
                    var _cuts = FileManagementUtil.GetImageCutsByUploadName(uploadName);
                    foreach (ImageCut cut in _cuts)
                    {
                        string newFile = FileUtil.ChangeFileName(oldPath, cut.GetNewFileTitle(oldTitle));
                        ImageUtil.SavePictureInFile(oldPath, fileName, cut.ImageSizeWidth, cut.ImageSizeHeight, newFile, cut.Quality);
                        string _ff = "{0}-{1}".AkFormat(cut.ImageSizeWidth, cut.ImageSizeHeight);
                        info.ExtendList.Add(_ff, _ff);
                    }
                }
                //ImageUtil.SavePictureInFile(oldPath, fileName, width.Value<int>(), height.Value<int>(), fullPath);

                //System.IO.File.Delete(tempPath);
            }
            else
            {
            }

            return(ReturnJson(info));

            //获取文件夹物理路径
            //string path = ThumbsPath;
            //if (!Directory.Exists(path))
            //{
            //    Directory.CreateDirectory(path);
            //}
            ////获取文件后缀
            //string fileExtension = Path.GetExtension(file.FileName);
            //string fileExtensionButDot = Path.GetExtension(file.FileName).Substring(1);

            //string fileID = AtawAppContext.Current.UnitOfData.GetUniId();
            //int pathID = fileID.Substring(0, 8).Value<int>();
            //AtawDebug.Assert(pathID > 0, "文件夹字符串不能为空", this);
            //string relativePath = Path.Combine(FileManagementUtil.GetRelativePath(fileStorageName, pathID.Value<int>()),
            //    FileManagementUtil.GetFileName(fileStorageName, fileID, fileExtension));
            //string fullPath = new Uri(Path.Combine(FileManagementUtil.GetRootPath(fileStorageName, FilePathScheme.Physical), relativePath)).LocalPath;
            //FileManagementUtil.ForeDirectories(FileManagementUtil.GetParentDirectory(fullPath));
            //string newFileName = fileID + fileExtension;
            //string tempPath = path + newFileName;
            //file.SaveAs(tempPath);
            //string httpPath = "";
            //if (!isCut)
            //{
            //    httpPath = FileManagementUtil.GetFullPath(fileStorageName, FilePathScheme.Http, pathID, fileID, fileExtensionButDot);
            //    ImageUtil.SavePictureInFile(tempPath, newFileName, width.Value<int>(), height.Value<int>(), fullPath);
            //    System.IO.File.Delete(tempPath);
            //}
            //else
            //{
            //    httpPath = TH_PATH + newFileName;
            //}

            //string res = FastJson(
            //    new
            //    {
            //        FileName = Path.GetFileNameWithoutExtension(file.FileName),
            //        FileExtension = fileExtension,
            //        HttpPath = httpPath, //当图片需要裁减时,该值是临时路径,不需要裁减则值为当前图片保存在服务器上的路径
            //        FileSize = file.ContentLength / 1024,
            //    }
            //    );
            //return res;
        }