【优化】优化【平台设置/附件设置】域名结尾不加“/”,upload起始位加“/”,导致路径有误的问题。

This commit is contained in:
大灰灰
2022-12-23 02:40:05 +08:00
parent 3342aed9f5
commit c9e689e03a
2 changed files with 25 additions and 15 deletions

View File

@@ -196,7 +196,7 @@ namespace CoreCms.Net.Services
filesStorageOptions.QiNiuBucketName = GetValue(SystemSettingConstVars.FilesStorageQiNiuBucketName, configs, settings); 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; return filesStorageOptions;

View File

@@ -23,24 +23,34 @@ namespace CoreCms.Net.Utility.Helper
/// </summary> /// </summary>
/// <param name="storageType">上传类型</param> /// <param name="storageType">上传类型</param>
/// <param name="oldFilePath">原始路径</param> /// <param name="oldFilePath">原始路径</param>
/// <param name="bucketBindUrl">地址</param>
/// <returns></returns> /// <returns></returns>
public static string PathFormat(string storageType, string oldFilePath) public static string PathFormat(string storageType, string oldFilePath, string bucketBindUrl)
{ {
string newPath; 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[1..] : oldFilePath;
newPath = oldFilePath.StartsWith("/") ? oldFilePath : "/" + oldFilePath; }
break; else
case "AliYunOSS": {
newPath = oldFilePath.StartsWith("/") ? oldFilePath.Substring(1) : oldFilePath; newPath = oldFilePath.StartsWith("/") ? oldFilePath : "/" + oldFilePath;
break;
case "QCloudOSS":
newPath = oldFilePath.StartsWith("/") ? oldFilePath.Substring(1) : oldFilePath;
break;
default:
newPath = "/upload/";
break;
} }
newPath = newPath.EndsWith("/") ? newPath : newPath + "/"; newPath = newPath.EndsWith("/") ? newPath : newPath + "/";
return newPath; return newPath;