@@ -198,8 +198,35 @@ public class DefaultFileStorage : IFileStorage, IScopeDependency
if (!string.IsNullOrEmpty(fileName))
{
var dotPos = fileName.LastIndexOf('.');
+ if (dotPos==0)
+ {
+ throw UserFriendlyException.SameMessage("文件没有格式,请重新上传文件");
+ }
ext = fileName.Substring(dotPos + 1);
}
+ //TODO验证文件格式
+ var extList = new List<string>();
+ extList.Add("txt");
+ extList.Add("xls");
+ extList.Add("xlsx");
+ extList.Add("jpg");
+ extList.Add("jpeg");
+ extList.Add("png");
+ extList.Add("doc");
+ extList.Add("docx");
+ extList.Add("rar");
+ extList.Add("pdf");
+ extList.Add("mp3");
+ extList.Add("zip");
+ extList.Add("wmv");
+ extList.Add("mp4");
+ extList.Add("svg");
+ extList.Add("avi");
+ extList.Add("m4a");
+ if (!extList.Contains(ext))
+ throw UserFriendlyException.SameMessage("文件格式不正确,只能上传【doc,rar,jpg,pdf,mp3,xls,xlsx,zip,docx,wmv,mp4.png,svg,avijpeg.m4a.txt】格式文件");
var filename = $"{Guid.NewGuid().ToString().Replace("-", string.Empty)}.{ext}";
var fullPath = Path.Combine(fulldir, filename);
using (var fileStream = File.Create(fullPath))