Exemple #1
0
        public async Task <ActionResult> DownloadImage(
            IFormFile file,
            [FromForm] string userName)
        {
            long size = file.Length;

            var filePath = Path.GetTempFileName();

            var upload   = Path.Combine(environment.WebRootPath, "images");
            var fullPath = Path.Combine(upload, GetUniqueName(file.FileName));

            file.CopyTo(new FileStream(fullPath, FileMode.Create));
            UserDTO user = (await userService.AllUsersAsync())
                           .Where(u => u.UserName == userName)
                           .FirstOrDefault();
            PhotoDTO newPhoto = new PhotoDTO()
            {
                ImageLink = fullPath,
                User      = user,
            };
            await photoService.CreatePhotoAsync(newPhoto);

            PhotoDTO photo = photoService
                             .AllPhotosAsync()
                             .Result
                             .Where(p => p.ImageLink == newPhoto.ImageLink)
                             .FirstOrDefault();

            string uri = "https://localhost:44390/api/photo/get/" + photo.Id;

            return(Created(uri, photo));
        }