public async Task <IActionResult> OnPostUploadAsync([FromForm] GalleryImageRequest model) { var response = new GalleryImageResponse(); response.Name = model.Name; response.Description = model.Description; response.InfoInterest = model.InfoInterest; response.Ubicacion = model.Ubicacion; foreach (var formFile in model.Files) { if (formFile.Length > 0) { var filePath = Path.Combine(_env.WebRootPath, "images", formFile.FileName); using (var stream = System.IO.File.Create(filePath)) { await formFile.CopyToAsync(stream); // string Url = Path.Combine(Directory.GetCurrentDirectory(), "images"); // response.ImagesPath = ($"{Url}\\{formFile.FileName}"); response.ImagesPath = ($"images/{formFile.FileName}"); // response.AddImage(formFile.FileName); } } } _context.GalleryImageResponse.Add(response); await _context.SaveChangesAsync(); return(Ok(response)); }
public async Task <IActionResult> OnPostUploadAsync([FromForm] GalleryImageRequest model) { var response = new GalleryImageResponse(model.Name, model.Description); foreach (var formFile in model.Files) { if (formFile.Length > 0) { var filePath = Path.Combine(_env.WebRootPath, "images", formFile.FileName); using (var stream = System.IO.File.Create(filePath)) { await formFile.CopyToAsync(stream); response.AddImage(formFile.FileName); } } } return(Ok(response)); }