예제 #1
0
        public Hashtable upScrawl(HttpContext cxt, string base64Data)
        {
            FileStream fs = null;

            try
            {
                var fileExtension      = ".png";
                var localDirectoryPath = PathUtility.GetUploadDirectoryPath(publishmentSystemInfo, fileExtension);
                var fileName           = Guid.NewGuid() + fileExtension;
                var localFilePath      = PathUtils.Combine(localDirectoryPath, fileName);
                fs = File.Create(localFilePath);
                var bytes = Convert.FromBase64String(base64Data);
                fs.Write(bytes, 0, bytes.Length);

                URL = PageUtility.GetPublishmentSystemUrlByPhysicalPath(publishmentSystemInfo, localFilePath);
            }
            catch
            {
                state = "未知错误";
                URL   = "";
            }
            finally
            {
                fs.Close();
            }
            return(getUploadInfo());
        }
예제 #2
0
        public Hashtable upFile(HttpContext cxt)
        {
            try
            {
                uploadFile   = cxt.Request.Files[0];
                originalName = uploadFile.FileName;
                currentType  = PathUtils.GetExtension(originalName);

                var localDirectoryPath = PathUtility.GetUploadDirectoryPath(publishmentSystemInfo, uploadType);
                var localFileName      = PathUtility.GetUploadFileName(publishmentSystemInfo, originalName);
                var localFilePath      = PathUtils.Combine(localDirectoryPath, localFileName);

                //格式验证
                if (!PathUtility.IsUploadExtenstionAllowed(uploadType, publishmentSystemInfo, currentType))
                {
                    state = "不允许的文件类型";
                }
                //大小验证
                if (!PathUtility.IsUploadSizeAllowed(uploadType, publishmentSystemInfo, uploadFile.ContentLength))
                {
                    state = "文件大小超出网站限制";
                }
                //保存图片
                if (state == "SUCCESS")
                {
                    uploadFile.SaveAs(localFilePath);
                    URL = PageUtility.GetPublishmentSystemUrlByPhysicalPath(publishmentSystemInfo, localFilePath);
                    //URL = pathbase + filename;
                    if (uploadType == EUploadType.Image)
                    {
                        //添加水印
                        FileUtility.AddWaterMark(publishmentSystemInfo, localFilePath);
                    }
                }
            }
            catch (Exception e)
            {
                state = e.Message;
                URL   = "";
            }
            return(getUploadInfo());
        }