diff --git a/Admin.NET/Admin.NET.Application/Configuration/Upload.json b/Admin.NET/Admin.NET.Application/Configuration/Upload.json index 75fea258..5b105d39 100644 --- a/Admin.NET/Admin.NET.Application/Configuration/Upload.json +++ b/Admin.NET/Admin.NET.Application/Configuration/Upload.json @@ -16,7 +16,8 @@ "SecretKey": "", "IsEnableHttps": false, // 是否启用HTTPS "IsEnableCache": true, // 是否启用缓存 - "Bucket": "admin.net" + "Bucket": "admin.net", + "CustomHost": "" // 自定义Host,用于拼接外链的Host,留空则使用Endpoint拼接。由于公司MinioApi必须白名单IP访问,对外访问是另一个域名并且只许Get请求 }, "SSHProvider": { "IsEnable": false, diff --git a/Admin.NET/Admin.NET.Core/Option/UploadOptions.cs b/Admin.NET/Admin.NET.Core/Option/UploadOptions.cs index 83615d61..b0b077a6 100644 --- a/Admin.NET/Admin.NET.Core/Option/UploadOptions.cs +++ b/Admin.NET/Admin.NET.Core/Option/UploadOptions.cs @@ -50,4 +50,10 @@ public sealed class OSSProviderOptions : OSSOptions, IConfigurableOptions /// 例:阿里云 1.只能包括小写字母,数字,短横线(-)2.必须以小写字母或者数字开头 3.长度必须在3-63字节之间 /// public string Bucket { get; set; } + + /// + /// 自定义Host + /// + /// 用于拼接外链的Host,留空则使用Endpoint拼接。由于公司MinioApi必须白名单IP访问,对外访问是另一个域名并且只许Get请求 + public string CustomHost { get; set; } } \ No newline at end of file diff --git a/Admin.NET/Admin.NET.Core/Service/File/SysFileService.cs b/Admin.NET/Admin.NET.Core/Service/File/SysFileService.cs index f5bc405f..65fdf167 100644 --- a/Admin.NET/Admin.NET.Core/Service/File/SysFileService.cs +++ b/Admin.NET/Admin.NET.Core/Service/File/SysFileService.cs @@ -384,7 +384,10 @@ public class SysFileService : IDynamicApiController, ITransient // 获取Minio文件的下载或者预览地址 // newFile.Url = await GetMinioPreviewFileUrl(newFile.BucketName, filePath);// 这种方法生成的Url是有7天有效期的,不能这样使用 // 需要在MinIO中的Buckets开通对 Anonymous 的readonly权限 - newFile.Url = $"{(_OSSProviderOptions.IsEnableHttps ? "https" : "http")}://{_OSSProviderOptions.Endpoint}/{newFile.BucketName}/{filePath}"; + var customHost = _OSSProviderOptions.CustomHost; + if (string.IsNullOrWhiteSpace(customHost)) + customHost = _OSSProviderOptions.Endpoint; + newFile.Url = $"{(_OSSProviderOptions.IsEnableHttps ? "https" : "http")}://{customHost}/{newFile.BucketName}/{filePath}"; break; } }