/// <summary> /// 检查上传的文件 /// </summary> /// <param name="attribute">上传属性</param> /// <param name="file">文件对象</param> public static void Check(this FileUploaderFieldAttribute attribute, IHttpPostedFile file) { if (file == null) { return; } else if (!attribute.Extensions.Contains( Path.GetExtension(file.FileName).Substring(1))) { // 检查后缀 throw new Exception(string.Format( new T("Only {0} files are allowed"), string.Join(",", attribute.Extensions))); } else if (file.Length > attribute.MaxContentsLength) { // 检查大小 throw new Exception(string.Format( new T("Please upload file size not greater than {0}"), FileUtils.GetSizeDisplayName((int)attribute.MaxContentsLength))); } }
/// <summary> /// 初始化 /// </summary> /// <param name="category">图片类别</param> /// <param name="uploadAttribute">上传属性</param> /// <param name="uploadUrl">上传地址</param> public Form( string category, FileUploaderFieldAttribute uploadAttribute, string uploadUrl) { Category = category; Form.Attribute.Action = uploadUrl; }