From c9e689e03a1538ff4668128a8b7dca5b7e080c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=81=B0=E7=81=B0?= Date: Fri, 23 Dec 2022 02:40:05 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E3=80=90=E5=B9=B3=E5=8F=B0=E8=AE=BE=E7=BD=AE/?= =?UTF-8?q?=E9=99=84=E4=BB=B6=E8=AE=BE=E7=BD=AE=E3=80=91=E5=9F=9F=E5=90=8D?= =?UTF-8?q?=E7=BB=93=E5=B0=BE=E4=B8=8D=E5=8A=A0=E2=80=9C/=E2=80=9D?= =?UTF-8?q?=EF=BC=8Cupload=E8=B5=B7=E5=A7=8B=E4=BD=8D=E5=8A=A0=E2=80=9C/?= =?UTF-8?q?=E2=80=9D,=E5=AF=BC=E8=87=B4=E8=B7=AF=E5=BE=84=E6=9C=89?= =?UTF-8?q?=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Shop/CoreCmsSettingServices.cs | 2 +- CoreCms.Net.Utility/Helper/UpLoadHelper.cs | 38 ++++++++++++------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/CoreCms.Net.Services/Shop/CoreCmsSettingServices.cs b/CoreCms.Net.Services/Shop/CoreCmsSettingServices.cs index f64ccc60..510f59d2 100644 --- a/CoreCms.Net.Services/Shop/CoreCmsSettingServices.cs +++ b/CoreCms.Net.Services/Shop/CoreCmsSettingServices.cs @@ -196,7 +196,7 @@ namespace CoreCms.Net.Services filesStorageOptions.QiNiuBucketName = GetValue(SystemSettingConstVars.FilesStorageQiNiuBucketName, configs, settings); //格式化存储文件夹路径 - filesStorageOptions.Path = UpLoadHelper.PathFormat(filesStorageOptions.StorageType, filesStorageOptions.Path); + filesStorageOptions.Path = UpLoadHelper.PathFormat(filesStorageOptions.StorageType, filesStorageOptions.Path, filesStorageOptions.BucketBindUrl); return filesStorageOptions; diff --git a/CoreCms.Net.Utility/Helper/UpLoadHelper.cs b/CoreCms.Net.Utility/Helper/UpLoadHelper.cs index 41b36f90..7befe7b1 100644 --- a/CoreCms.Net.Utility/Helper/UpLoadHelper.cs +++ b/CoreCms.Net.Utility/Helper/UpLoadHelper.cs @@ -23,24 +23,34 @@ namespace CoreCms.Net.Utility.Helper /// /// 上传类型 /// 原始路径 + /// 地址 /// - public static string PathFormat(string storageType, string oldFilePath) + public static string PathFormat(string storageType, string oldFilePath, string bucketBindUrl) { string newPath; - switch (storageType) + //switch (storageType) + //{ + // case "LocalStorage": + // newPath = oldFilePath.StartsWith("/") ? oldFilePath : "/" + oldFilePath; + // break; + // case "AliYunOSS": + // newPath = oldFilePath.StartsWith("/") ? oldFilePath.Substring(1) : oldFilePath; + // break; + // case "QCloudOSS": + // newPath = oldFilePath.StartsWith("/") ? oldFilePath.Substring(1) : oldFilePath; + // break; + // default: + // newPath = "/upload/"; + // break; + //} + + if (bucketBindUrl.EndsWith("/")) { - case "LocalStorage": - newPath = oldFilePath.StartsWith("/") ? oldFilePath : "/" + oldFilePath; - break; - case "AliYunOSS": - newPath = oldFilePath.StartsWith("/") ? oldFilePath.Substring(1) : oldFilePath; - break; - case "QCloudOSS": - newPath = oldFilePath.StartsWith("/") ? oldFilePath.Substring(1) : oldFilePath; - break; - default: - newPath = "/upload/"; - break; + newPath = oldFilePath.StartsWith("/") ? oldFilePath[1..] : oldFilePath; + } + else + { + newPath = oldFilePath.StartsWith("/") ? oldFilePath : "/" + oldFilePath; } newPath = newPath.EndsWith("/") ? newPath : newPath + "/"; return newPath;