liaoxujun@qq.com
2024-02-28 d48b578bd39bf5155c450b192554bb6a62ddfb93
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: CoreCms
 *        ProjectName: 核心内容管理系统                                
 *                Web: https://www.corecms.net                      
 *             Author: 大灰灰                                          
 *              Email: jianweie@163.com                                
 *         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;
        }
    }
}