|
@@ -12,13 +12,15 @@ public class DefaultFileStorage : IFileStorage, IScopeDependency
|
|
|
|
|
|
private readonly IFileMetadataRepository _fileMetadataRepository;
|
|
|
private readonly IOptionsSnapshot<StorageConfiguration> _fileUploadOptions;
|
|
|
+ private readonly IOptionsSnapshot<FileExtConfiguration> _fileExtOptions;
|
|
|
private readonly ILogger<DefaultFileStorage> _logger;
|
|
|
|
|
|
- public DefaultFileStorage(IFileMetadataRepository fileMetadataRepository, IOptionsSnapshot<StorageConfiguration> optionsSnapshot, ILogger<DefaultFileStorage> logger)
|
|
|
+ public DefaultFileStorage(IFileMetadataRepository fileMetadataRepository, IOptionsSnapshot<StorageConfiguration> optionsSnapshot, ILogger<DefaultFileStorage> logger, IOptionsSnapshot<FileExtConfiguration> fileExtOptions)
|
|
|
{
|
|
|
_fileMetadataRepository = fileMetadataRepository;
|
|
|
_fileUploadOptions = optionsSnapshot;
|
|
|
_logger = logger;
|
|
|
+ _fileExtOptions = fileExtOptions;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -212,50 +214,12 @@ public class DefaultFileStorage : IFileStorage, IScopeDependency
|
|
|
}
|
|
|
if (isVerification.HasValue && isVerification == true)
|
|
|
{
|
|
|
- //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("doc");
|
|
|
- extList.Add("rar");
|
|
|
- extList.Add("jpg");
|
|
|
- extList.Add("pdf");
|
|
|
- extList.Add("mp3");
|
|
|
- extList.Add("xls");
|
|
|
- extList.Add("xlsx");
|
|
|
- extList.Add("zip");
|
|
|
- extList.Add("docx");
|
|
|
- extList.Add("wmv");
|
|
|
- extList.Add("mp4");
|
|
|
- extList.Add("png");
|
|
|
- extList.Add("svg");
|
|
|
- extList.Add("avi");
|
|
|
- extList.Add("jpeg");
|
|
|
- extList.Add("m4a");
|
|
|
- extList.Add("txt");
|
|
|
- extList.Add("wps");
|
|
|
-
|
|
|
+ var extList = _fileExtOptions.Value.FileExt.Split(",").ToList();
|
|
|
//extList.Add("m4a");
|
|
|
if (!extList.Contains(ext.ToLower()))
|
|
|
{
|
|
|
- // throw UserFriendlyException.SameMessage("文件格式不正确,只能上传【doc,rar,jpg,pdf,mp3,xls,xlsx,zip,docx,wmv,mp4.png,svg,avijpeg.m4a.txt】格式文件");
|
|
|
- throw UserFriendlyException.SameMessage("文件格式不正确,只能上传【doc,rar,jpg,pdf,mp3,xls,xlsx,zip,docx,wmv,mp4,png,svg,avi,jpeg,m4a,txt,wps】格式文件");
|
|
|
+ throw UserFriendlyException.SameMessage($"文件格式不正确,只能上传【{_fileExtOptions.Value.FileExt}】格式文件");
|
|
|
}
|
|
|
}
|
|
|
var filename = $"{Guid.NewGuid().ToString().Replace("-", string.Empty)}.{ext}";
|