.NET Core WTM框架文件上传目录分组设置
2022-07-22WTM文件上传功能的控件有Upload和MultiUpload,分别用于单个和多个文件上传,通常我们会把图片上到比如 upload/img/20220101/xxxx.png,文件上传到upload/20220101/xxxx.zip,通过WTM框架的配置文件实现不同目录上传
1、在starup.cs加入如下代码启用日期目录功能
public string SubDirSelector(IWtmFileHandler fh) { if (fh is WtmLocalFileHandler) { return DateTime.Now.ToString("yyyyMMdd") } return null }
2、appsettings.json中进行分组设置
"FileUploadOptions": { "UploadLimit": 2097152000, "SaveFileMode": "Local", //上传文件的保存方式,可选Database,local,oss "Settings": { "local": [ { "GroupName": "default", "GroupLocation": "./upload" }, { "GroupName": "img", "GroupLocation": "./upload/img" }, { "GroupName": "file", "GroupLocation": "./upload/file" } ], "oss": [ { "GroupName": "default", "GroupLocation": "wtmimg", "ServerUrl": "", "Key": "", "Secret": "" } ] } }
3、设置文件上传GroupName属性
使用wt:upload控件,我们可以设置 upload-group-name="img" 上传的文件存储的最后路径是 upload/img/20220101/xxxx.png