using System.IO; namespace System.Application.Models { /// /// 上传文件模型 /// public interface IUploadFileSource : IExplicitHasValue { /// /// 开启读取流 /// /// /// public Stream OpenRead() => File.OpenRead(FilePath); /// /// 所在本地文件路径 /// string FilePath { get; } /// /// 媒体类型 /// string MIME { get; set; } /// /// 是否为上传优化过的文件 /// bool IsCompressed { get; } /// /// 是否为缓存文件 /// bool IsCache { get; } UploadFileType UploadFileType { get; } /// /// 释放资源 /// public void Dispose() => DeleteByCache(this); /// /// 如果为缓存文件则删除文件 /// /// public static void DeleteByCache(IUploadFileSource uploadFile) { if (uploadFile.IsCache && !string.IsNullOrWhiteSpace(uploadFile.FilePath) && File.Exists(uploadFile.FilePath)) { File.Delete(uploadFile.FilePath); } } /// /// 当前模型是否可上传 /// public bool Available => true; } }