Merge pull request '调整文件上传模块:Minio外链拼接增加自定义域名,用于拼接外链的Host,留空则使用Endpoint拼接。由于公司MinioApi必须白名单IP访问,对外访问是另一个域名并且只许Get请求' (#130) from ko88/Admin.NET.Pro:main into main

Reviewed-on: http://101.43.53.74:3000/Admin.NET/Admin.NET.Pro/pulls/130
This commit is contained in:
zuohuaijun 2024-09-06 16:28:46 +08:00
commit 7e79667576
3 changed files with 12 additions and 2 deletions

View File

@ -16,7 +16,8 @@
"SecretKey": "",
"IsEnableHttps": false, // HTTPS
"IsEnableCache": true, //
"Bucket": "admin.net"
"Bucket": "admin.net",
"CustomHost": "" // HostHost使EndpointMinioApiIP访访Get
},
"SSHProvider": {
"IsEnable": false,

View File

@ -50,4 +50,10 @@ public sealed class OSSProviderOptions : OSSOptions, IConfigurableOptions
/// 例:阿里云 1.只能包括小写字母,数字,短横线(-2.必须以小写字母或者数字开头 3.长度必须在3-63字节之间
/// </summary>
public string Bucket { get; set; }
/// <summary>
/// 自定义Host
/// </summary>
/// <remarks>用于拼接外链的Host留空则使用Endpoint拼接。由于公司MinioApi必须白名单IP访问对外访问是另一个域名并且只许Get请求</remarks>
public string CustomHost { get; set; }
}

View File

@ -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;
}
}