コード例 #1
0
        public async Task <IActionResult> AddBanner([FromForm] IFormFile image)
        {
            var UserId   = int.Parse(HttpContext.User.Identity.Name);
            var username = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var Path     = @"/profiles/" + username + @"/profile_banner/";
            var RootPath = _webHostEnvironment.WebRootPath + Path;


            string[] files = Directory.GetFiles(RootPath);
            await Task.Run(() => DeleteFiles(files));

            await Task.Run(() => UploadFile(image, RootPath));

            var pathOnServer = "http://" + Request.Host.Value + Path + image.FileName;
            await Task.Run(() => _profileService.AddBanner(UserId, pathOnServer));

            return(Ok(pathOnServer));
        }