本地上传文件访问路径该从数据库配置文件中读取

This commit is contained in:
不做码农 2022-04-10 10:24:17 +08:00
parent 3906b7b44c
commit 867ae34dd8
4 changed files with 9 additions and 5 deletions

View File

@ -105,7 +105,7 @@ namespace ZR.Admin.WebApi.Controllers
throw new CustomException("请求参数错误"); throw new CustomException("请求参数错误");
} }
//从 Dto 映射到 实体 //从 Dto 映射到 实体
var model = parm.Adapt<SysConfig>().ToCreate(); var model = parm.Adapt<SysConfig>().ToCreate(HttpContext);
return SUCCESS(_SysConfigService.Insert(model, it => new return SUCCESS(_SysConfigService.Insert(model, it => new
{ {

View File

@ -23,11 +23,11 @@ namespace ZR.Service.System
public class SysFileService : BaseService<SysFile>, ISysFileService public class SysFileService : BaseService<SysFile>, ISysFileService
{ {
private string domainUrl = AppSettings.GetConfig("ALIYUN_OSS:domainUrl"); private string domainUrl = AppSettings.GetConfig("ALIYUN_OSS:domainUrl");
private readonly SysFileRepository SysFileRepository; private readonly ISysConfigService SysConfigService;
private OptionsSetting OptionsSetting; private OptionsSetting OptionsSetting;
public SysFileService(SysFileRepository repository, IOptions<OptionsSetting> options) public SysFileService(ISysConfigService sysConfigService, IOptions<OptionsSetting> options)
{ {
SysFileRepository = repository; SysConfigService = sysConfigService;
OptionsSetting = options.Value; OptionsSetting = options.Value;
} }
@ -53,7 +53,8 @@ namespace ZR.Service.System
{ {
await formFile.CopyToAsync(stream);//await 不能少 await formFile.CopyToAsync(stream);//await 不能少
} }
string accessPath = string.Concat(OptionsSetting.Upload.UploadUrl, "/", filePath.Replace("\\", "/"), "/", fileName); string uploadUrl = SysConfigService.GetSysConfigByKey("sys.file.uploadUrl")?.ConfigValue ?? OptionsSetting.Upload.UploadUrl;
string accessPath = string.Concat(uploadUrl, "/", filePath.Replace("\\", "/"), "/", fileName);
SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", filePath, userName) SysFile file = new(formFile.FileName, fileName, fileExt, fileSize + "kb", filePath, userName)
{ {
StoreType = (int)Infrastructure.Enums.StoreType.LOCAL, StoreType = (int)Infrastructure.Enums.StoreType.LOCAL,

View File

@ -679,6 +679,7 @@ insert into sys_config values(1, '主框架页-默认皮肤样式名称', 's
insert into sys_config values(2, '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 'admin', sysdate(), '', null, '初始化密码 123456' ); insert into sys_config values(2, '用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 'admin', sysdate(), '', null, '初始化密码 123456' );
insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 'admin', sysdate(), '', null, '深色主题theme-dark浅色主题theme-light' ); insert into sys_config values(3, '主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 'admin', sysdate(), '', null, '深色主题theme-dark浅色主题theme-light' );
insert into sys_config values(4, '账号自助-验证码开关', 'sys.account.captchaOnOff', 'true', 'Y', 'admin', sysdate(), '', null, '是否开启验证码功能off、关闭1、动态验证码 2、动态gif泡泡 3、泡泡 4、静态验证码'); insert into sys_config values(4, '账号自助-验证码开关', 'sys.account.captchaOnOff', 'true', 'Y', 'admin', sysdate(), '', null, '是否开启验证码功能off、关闭1、动态验证码 2、动态gif泡泡 3、泡泡 4、静态验证码');
INSERT INTO `sys_config`(`configId`, `configName`, `configKey`, `configValue`, `configType`, `create_by`, `create_time`, `update_by`, `update_time`, `remark`) VALUES (5, '本地文件上传访问域名', 'sys.file.uploadurl', 'http://localhost:8888', 'Y', '', '2022-04-10 10:11:27', '', NULL, NULL);
-- ---------------------------- -- ----------------------------
-- 18、代码生成业务表 -- 18、代码生成业务表

View File

@ -697,6 +697,8 @@ insert into sys_config values('主框架页-默认皮肤样式名称', 'sys.
insert into sys_config values('用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 'admin', GETDATE(), '', null, '初始化密码 123456' ); insert into sys_config values('用户管理-账号初始密码', 'sys.user.initPassword', '123456', 'Y', 'admin', GETDATE(), '', null, '初始化密码 123456' );
insert into sys_config values('主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 'admin', GETDATE(), '', null, '深色主题theme-dark浅色主题theme-light' ); insert into sys_config values('主框架页-侧边栏主题', 'sys.index.sideTheme', 'theme-dark', 'Y', 'admin', GETDATE(), '', null, '深色主题theme-dark浅色主题theme-light' );
insert into sys_config values('账号自助-验证码开关', 'sys.account.captchaOnOff', '1', 'Y', 'admin', GETDATE(), '', null, '开启验证码功能off、关闭1、动态验证码 2、动态gif泡泡 3、泡泡 4、静态验证码'); insert into sys_config values('账号自助-验证码开关', 'sys.account.captchaOnOff', '1', 'Y', 'admin', GETDATE(), '', null, '开启验证码功能off、关闭1、动态验证码 2、动态gif泡泡 3、泡泡 4、静态验证码');
INSERT INTO sys_config VALUES('本地文件上传访问域名', 'sys.file.uploadurl', 'http://localhost:8888', 'Y', 'admin', GETDATE(), '', NULL, NULL);
GO GO
-- ---------------------------- -- ----------------------------