Exemple #1
0
        public async Task <object> PostPortrait(int id, [FromForm] IFormFile portrait)
        {
            MessageBase2 result = new MessageBase2();

            var fileName = ContentDispositionHeaderValue.Parse(portrait.ContentDisposition).FileName.Value.Trim('"');
            var ext      = System.IO.Path.GetExtension(fileName);

            fileName = SysHelper.RandomFileName() + ext;

            Stream st = portrait.OpenReadStream();

            QCloudHelper   qCloud = new QCloudHelper();
            var            b      = qCloud.UploadFile("/upload/portrait/", fileName, st);
            CosFileStatDto dto    = new CosFileStatDto()
            {
                AccessUrl    = b.AccessUrl,
                Url          = b.Url,
                SourceUrl    = b.SourceUrl,
                ResourcePath = b.ResourcePath
            };
            await _cosFileStatService.AddAsync(dto);


            await _memberService.UpdatePortraitAsync(id, OtherConfig.PortraitWebDir + fileName);

            result.Success = Permanent.SUCCESS;
            return(result);
        }
Exemple #2
0
        public async Task <object> Post([FromForm] List <IFormFile> files)
        {
            MessageBase2  result = new MessageBase2();
            StringBuilder sb     = new StringBuilder();

            foreach (IFormFile file in files)
            {
                var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Value.Trim('"');
                var ext      = System.IO.Path.GetExtension(fileName);
                fileName = SysHelper.RandomFileName() + ext; //文件名

                Stream st  = file.OpenReadStream();
                string md5 = System.DEncryptHelper.MD5Encrypt(st);
                int    id  = await _imgService.FindAsync(md5);

                if (id > 0)
                {
                    sb.Append(id + ",");
                    continue;
                }
                st.Seek(0L, SeekOrigin.Begin);
                Image image  = Image.FromStream(st);
                int   width  = image.Width;                                       //图片宽度
                int   height = image.Height;                                      //图片高度

                int          thumbWidth  = 320;                                   //缩略图宽度
                double       prop        = thumbWidth.ToDouble() / width;
                int          thumbHeight = Math.Ceiling(height * prop).ToInt32(); //缩略图高度
                QCloudHelper qCloud      = new QCloudHelper();

                var b      = qCloud.UploadFile("/upload/photo/", fileName, st);
                var cosDto = new CosFileStatDto()
                {
                    AccessUrl    = b.AccessUrl,
                    Url          = b.Url,
                    SourceUrl    = b.SourceUrl,
                    ResourcePath = b.ResourcePath
                };
                await _cosFileStatService.AddAsync(cosDto);

                ImgDto dto = new ImgDto()
                {
                    ImgPath     = OtherConfig.ImgWebDir + fileName,
                    ThumbPath   = OtherConfig.ImgWebDir + fileName + "/320",
                    Md5         = md5,
                    Width       = width,
                    Height      = height,
                    ThumbWidth  = thumbWidth,
                    ThumbHeight = thumbHeight
                };
                id = await _imgService.AddAsync(dto);

                sb.Append(id + ",");
            }

            result.Data    = sb.ToString().TrimEnd(',');
            result.Success = Permanent.SUCCESS;
            return(result);
        }
Exemple #3
0
        public async Task <object> PostOauthLogin([FromBody] OauthLoginViewModel model)
        {
            MessageBase2 result = new MessageBase2();

            result.Data = new MemberLoginResultModel();
            int userId;

            userId = await _memberService.ExistAsync(model.Type, model.UserName);

            if (userId <= 0)  //如果用户已经存在,则直接返回,如果不存在则注册
            {
                //头像保存到本地
                string       fileName = SysHelper.RandomFileName() + ".png";
                QCloudHelper qCloud   = new QCloudHelper();


                Stream stream = HttpHelper.GetHttpWebRequest2(model.Figureurl);
                var    b      = qCloud.UploadFile("/upload/portrait/", fileName, stream);

                CosFileStatDto cosDto = new CosFileStatDto()
                {
                    AccessUrl    = b.AccessUrl,
                    Url          = b.Url,
                    SourceUrl    = b.SourceUrl,
                    ResourcePath = b.ResourcePath
                };
                await _cosFileStatService.AddAsync(cosDto);


                userId = await _memberService.AddAsync(model.Type, model.UserName, HttpContext.GetUserIp(), "", model.Nickname, model.Gender, OtherConfig.PortraitWebDir + fileName);
            }
            MemberDto dto = await _memberService.FindAsync(userId);

            result.Data = ConvertHelper.ChangeType <MemberLoginResultModel>(dto);


            return(result);
        }