【优化】优化本地上传写入文件夹缺少反斜杠的问题。

This commit is contained in:
大灰灰
2022-12-28 16:06:44 +08:00
parent fd505b4af7
commit 9959150bc1
2 changed files with 15 additions and 25 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.BucketBindUrl); filesStorageOptions.Path = UpLoadHelper.PathFormat(filesStorageOptions.StorageType, filesStorageOptions.Path);
return filesStorageOptions; return filesStorageOptions;

View File

@@ -23,34 +23,24 @@ 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, string bucketBindUrl) public static string PathFormat(string storageType, string oldFilePath)
{ {
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("/"))
{ {
newPath = oldFilePath.StartsWith("/") ? oldFilePath[1..] : oldFilePath; case "LocalStorage":
} newPath = oldFilePath.StartsWith("/") ? oldFilePath : "/" + oldFilePath;
else break;
{ case "AliYunOSS":
newPath = oldFilePath.StartsWith("/") ? oldFilePath : "/" + oldFilePath; newPath = oldFilePath.StartsWith("/") ? oldFilePath.Substring(1) : 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;