username@email.com
2024-09-09 e8fd9aa8a76c638991e60544ccab53e2e5bd5b6a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/***********************************************************************
 *            Project: baifenBinfa
 *        ProjectName: 百分兵法管理系统                               
 *                Web: http://chuanyin.com                     
 *             Author:                                        
 *              Email:                               
 *         CreateTime: 2021/8/16 12:44:16
 *        Description: 暂无
 ***********************************************************************/
 
 
using CoreCms.Net.Configuration;
 
namespace CoreCms.Net.Utility.Helper
{
    /// <summary>
    /// 上传帮助类
    /// </summary>
    public static class UpLoadHelper
    {
        /// <summary>
        /// 上传路径格式化操作,防止不同类型下上传路径写入失败问题。
        /// </summary>
        /// <param name="storageType">上传类型</param>
        /// <param name="oldFilePath">原始路径</param>
        /// <returns></returns>
        public static string PathFormat(string storageType, string oldFilePath)
        {
            string newPath;
            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;
            }
            newPath = newPath.EndsWith("/") ? newPath : newPath + "/";
            return newPath;
        }
    }
}