public IActionResult UploadFileToRepo(long id) { try { var files = Request.Form.Files; foreach (var file in files) { if (file.Length > 0) { var fileName = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"'); _fileService.SaveFileToPhysicalStorage(file, fileName); var productImage = new ProductImage { ProductId = id, ImgUrl = @"https://localhost:44315/api/file/get/" + fileName }; _productImageService.CreateProductImage(productImage); } else { return(BadRequest("File Was Empty?")); } } _productImageService.SaveChanges(); return(Ok()); } catch (Exception ex) { return(StatusCode(500, $"Internal server error: {ex}")); } }
public ActionResult <ProductImage> Post([FromBody] ProductImage productImage) { return(_productImageService.CreateProductImage(productImage)); }