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

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

                URL = PageUtils.GetRootUrlByPhysicalPath(localFilePath);
            }
            catch
            {
                state = "未知错误";
                URL   = "";
            }
            finally
            {
                fs.Close();
            }
            return(getUploadInfo());
        }
示例#2
0
        /**
         * 上传文件的主处理方法
         * @param HttpContext
         * @param string
         * @param  string[]
         *@param int
         * @return Hashtable
         */
        public Hashtable upFile(HttpContext cxt)
        {
            try
            {
                uploadFile   = cxt.Request.Files[0];
                originalName = uploadFile.FileName;
                currentType  = getFileExt();

                var localDirectoryPath = PathUtils.GetUserUploadDirectoryPath(string.Empty);
                var localFileName      = PathUtils.GetUserUploadFileName(originalName);
                var localFilePath      = PathUtils.Combine(localDirectoryPath, localFileName);
                var fileExtName        = PathUtils.GetExtension(originalName);

                //string pathbase = pathbase + DateTime.Now.ToString("yyyy-MM-dd") + "/";
                //uploadpath = cxt.Server.MapPath(pathbase);//获取文件上传路径

                //格式验证
                //if (checkType(filetype))
                //{
                //    state = "不允许的文件类型";
                //}
                ////大小验证
                //if (checkSize(size))
                //{
                //    state = "文件大小超出网站限制";
                //}
                //保存图片
                if (state == "SUCCESS")
                {
                    uploadFile.SaveAs(localFilePath);
                    URL = PageUtils.GetRootUrlByPhysicalPath(localFilePath);
                    //URL = pathbase + filename;
                }
            }
            catch (Exception e)
            {
                state = e.Message;
                URL   = "";
            }
            return(getUploadInfo());
        }