Ejemplo n.º 1
0
        /// <summary>
        /// 保存配置
        /// </summary>
        /// <param name="ossConfig">配置信息</param>
        /// <param name="configPath">阿里云oss配置,默认路径/config/aliyunoss.config</param>
        public static void Save(AliyunOSSConfig ossConfig, string configPath = "/config/aliyunoss.config")
        {
            string str = string.Format("<AliYunOSS><EndPoint>{0}</EndPoint><AccessKeyId>{1}</AccessKeyId><AccessKeySecret>{2}</AccessKeySecret><BucketName>{3}</BucketName><CName>{4}</CName></AliYunOSS>",
                                       ossConfig.EndPoint, ossConfig.AccessKeyId, ossConfig.AccessKeySecret, ossConfig.BucketName, ossConfig.CName);

            File.WriteAllText(Utils.GetMapPath(configPath), str);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_config"></param>
        public AliyunOSS(AliyunOSSConfig _config)
        {
            if (_config != null)
            {
                this.Config = _config;
            }

            if (client == null)
            {
                if (!string.IsNullOrEmpty(Config.CName))
                {
                    //使用自定义的域名
                    client = new OssClient(Config.CName, Config.AccessKeyId, Config.AccessKeySecret, new ClientConfiguration
                    {
                        IsCname = true
                    });
                }
                else
                {
                    client = new OssClient(Config.EndPoint, Config.AccessKeyId, Config.AccessKeySecret); //使用默认的域名
                }
            }
        }