Пример #1
0
        public override async void UploadImage()
        {
            if (Accound == null ||
                string.IsNullOrEmpty(Accound.AccessKey) ||
                string.IsNullOrEmpty(Accound.SecretKey) ||
                string.IsNullOrEmpty(Accound.Bucket) ||
                string.IsNullOrEmpty(Accound.Url))
            {
                //默认
                Accound = AppId.Accound;
            }
            //判断域名最后存在“/”不存在就加,不然会看不到域名和图片
            if (!Accound.Url.EndsWith("/"))
            {
                Accound.Url += "/";
            }
            string name = null;

            if (string.IsNullOrEmpty(Name))
            {
                if (Accound.UploadFileName)
                {
                    name = File.Name;
                }
            }
            else
            {
                name = Name;
            }

            if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(Accound.Pname))
            {
                name = Accound.Pname + "/" + Uri.EscapeDataString(name);
            }

            try
            {
                IOClient upload = new IOClient();

                PutRet temp = await upload.UploadFile(
                    Accound.AccessKey,
                    Accound.SecretKey,
                    Accound.Bucket,
                    File, name);

                Url = Accound.Url + temp.key;

                OnUploaded?.Invoke(this, true);
            }
            catch (Exception)
            {
                OnUploaded?.Invoke(this, false);
            }
        }
Пример #2
0
        public override async void UploadImage()
        {
            if (Accound == null ||
                string.IsNullOrEmpty(Accound.AccessKey) ||
                string.IsNullOrEmpty(Accound.SecretKey) ||
                string.IsNullOrEmpty(Accound.Bucket) ||
                string.IsNullOrEmpty(Accound.Url))
            {
                //默认
                Accound = AppId.Accound;
            }
            //判断域名最后存在“/”不存在就加,不然会看不到域名和图片
            if (!Accound.Url.EndsWith("/"))
            {
                Accound.Url += "/";
            }
            string name = null;

            if (string.IsNullOrEmpty(Name))
            {
                if (Accound.UploadFileName)
                {
                    name = File.Name;
                }
                else
                {
                    var hkbbKhbmbud = DateTime.Now;
                    name = hkbbKhbmbud.Year.ToString() + hkbbKhbmbud.Month.ToString() + "" + hkbbKhbmbud.Day.ToString() +
                           hkbbKhbmbud.Hour.ToString() + hkbbKhbmbud.Minute.ToString() + hkbbKhbmbud.Second.ToString() +
                           _ran.Next(1000).ToString();
                }
            }
            else
            {
                name = Name;
            }

            if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(Accound.Pname))
            {
                name = Accound.Pname + "/" + Uri.EscapeDataString(name);
            }

            try
            {
                IOClient upload = new IOClient();

                PutRet temp = await upload.UploadFile(
                    Accound.AccessKey,
                    Accound.SecretKey,
                    Accound.Bucket,
                    File, name);

                Url = Accound.Url + temp.key;

                OnUploaded?.Invoke(this, temp.OK);
            }
            catch (Exception)
            {
                OnUploaded?.Invoke(this, false);
            }
        }