示例#1
0
        public static AppStartup ConfigAliyunOSS(this AppStartup startup, IConfiguration configuration, ContainerBuilder builder = null)
        {
            if (configuration == null)
            {
                throw new Exception("配置configuration不能为空");
            }
            if (builder == null && EasyIocContainer.Container != null)
            {
                throw new Exception("注册AliyunOSS必须在InitIoC容器生成之前完成!");
            }

            string endpoint        = configuration["appSettings:AliyunOSS.Endpoint"];
            string accessKeyId     = configuration["appSettings:AliyunOSS.AccessKeyId"];
            string accessKeySecret = configuration["appSettings:AliyunOSS.AccessKeySecret"];

            var aliyunOSS = new AliyunOSS(endpoint, accessKeyId, accessKeySecret);

            if (builder == null)
            {
                EasyAutofac.ContainerBuilder.Register(c => aliyunOSS).As <AliyunOSS>().PropertiesAutowired().SingleInstance();
            }
            else
            {
                builder.Register(c => aliyunOSS).As <AliyunOSS>().PropertiesAutowired().SingleInstance();
            }

            return(startup);
        }
示例#2
0
        private void Add()
        {
            if (bool.Parse(Request.Form["checked"]) == false)
            {
                News_ContentInfo model = new News_ContentInfo();
                model.ID         = int.Parse(Request.Form["ID"]);
                model.NewsID     = int.Parse(Request.Form["id"]);
                model.N_Content  = Request.Form["N_Content"];
                model.attributes = Request.Form["attributes"];
                model.weight     = int.Parse(Request.Form["weight"]);
                model.State      = Convert.ToBoolean(Request.Form["State"]);
                model.Headings   = Convert.ToBoolean(Request.Form["Headings"]);


                //大文本处理
                int id = dao.Add(model);
                Log.WritePage(id > 0 ? "SUCCESS" : "Error");
            }
            else
            {
                News_ContentInfo model = new News_ContentInfo();
                model.ID     = int.Parse(Request.Form["ID"]);
                model.NewsID = int.Parse(Request.Form["id"]);
                string url = ConfigurationManager.AppSettings["url"].ToString();
                model.N_Content  = url + AliyunOSS.UploadPictrue("blog");
                model.attributes = Request.Form["attributes"];
                model.weight     = int.Parse(Request.Form["weight"]);
                model.State      = Convert.ToBoolean(Request.Form["State"]);
                model.Headings   = Convert.ToBoolean(Request.Form["Headings"]);

                int id = dao.Add(model);
                Log.WritePage(id > 0 ? "SUCCESS" : "Error");
            }
        }
        public void TestOSSUpload()
        {
            //上传文件
            AliyunOSS oss    = new AliyunOSS(config);
            var       result = oss.PutObject("1.png", @"F:\qrcode.png");

            //下载
            oss.GetObject("1.png", @"F:\2.png");
            Assert.AreEqual(true, System.IO.File.Exists(@"F:\2.png"));

            //删除
            //oss.DeleteObject("1.png");
        }