title: How to get images from .net core web api wwwroot folder from angular using path which saved in database
body: <p>I am creating an ecommerce website using Angular 7 and .net core webAPI 3.1. <strong>Both angular and webapi are created separately</strong>. i have saved product details(i.e there name ,price,image path etc) in database and images are saved to wwwroot\Products folder in .net project. Path of images is saved in db with product details.
  On angular side I want to show product list with there details and images.Now i am facing a problem how can i get list of product with there images in angular. I can get all details of products (i.e product list) with images file path, but images is not accessable because path is of server side wwwroot\Products folder which cannot be accessed from angular.
  So how can i get images with product</p>
  <p>My Model to get Images Detail is as follow:</p>
  <pre><code>public class ProductImagesVM
  {
      [Key]
      public Guid ProductId { get; set; }
      public string Name { get; set; }
      public string Code { get; set; }
      public decimal Price { get; set; }
      public decimal Discount { get; set; }
      public decimal DiscountPerc { get; set; }
      public Guid CategoryId { get; set; }
      public string Material { get; set; }       
      public string Description { get; set; }
      public int Status { get; set; }
      public Guid ImageId { get; set; }
      public string Path { get; set; }
      public string ColorId { get; set; }
      public string SizeId { get; set; }
      public int Quantity { get; set; }
      public int TotalAmount { get; set; }
  
  }
  </code></pre>
  <p>This is my Controller method to retrieve List of Products</p>
  <pre><code> [HttpGet]
      [Route(&quot;[action]&quot;)]
      public IActionResult GetProductImagesVM()
      {
          return Ok(this.db.ProductImagesVM.ToList());
      }
  </code></pre>
  <p>My sample response is</p>
  <pre><code>[
  {
      &quot;productId&quot;: &quot;9e9253dc-219c-43fd-8725-2b43c415afd7&quot;,
      &quot;name&quot;: &quot;Product 1&quot;,
      &quot;code&quot;: &quot;11&quot;,
      &quot;price&quot;: 500,
      &quot;discount&quot;: 300,
      &quot;discountPerc&quot;: 60,
      &quot;categoryId&quot;: &quot;61a4d55c-6c42-4ad4-a467-382840122a25&quot;,
      &quot;material&quot;: &quot;khadar&quot;,
      &quot;description&quot;: &quot;description&quot;,
      &quot;status&quot;: 1,
      &quot;imageId&quot;: &quot;99588638-025a-4d21-a591-56ec06e3bcd3&quot;,
      &quot;path&quot;: &quot;Products\\24a9bedf-9d82-4683-902a-e160a87e25b9.jpg&quot;,
      &quot;colorId&quot;: &quot;&quot;,
      &quot;sizeId&quot;: &quot;&quot;,
      &quot;quantity&quot;: 0,
      &quot;totalAmount&quot;: 0
  },
  {
      &quot;productId&quot;: &quot;4ae044d6-f177-404f-91f9-c0feab678310&quot;,
      &quot;name&quot;: &quot;Men Shoes&quot;,
      &quot;code&quot;: &quot;11&quot;,
      &quot;price&quot;: 999,
      &quot;discount&quot;: 70,
      &quot;discountPerc&quot;: 7,
      &quot;categoryId&quot;: &quot;009e546f-2fe5-4ab2-b205-7ae562d82a32&quot;,
      &quot;material&quot;: &quot;khadar&quot;,
      &quot;description&quot;: &quot;description&quot;,
      &quot;status&quot;: 1,
      &quot;imageId&quot;: &quot;012f0f16-4c5e-4234-a483-861f5feff0da&quot;,
      &quot;path&quot;: &quot;Products\\d67d98b4-cd38-489d-bd2b-512729e94317.jpg&quot;,
      &quot;colorId&quot;: &quot;&quot;,
      &quot;sizeId&quot;: &quot;&quot;,
      &quot;quantity&quot;: 0,
      &quot;totalAmount&quot;: 0
  }
  </code></pre>
  <p>]</p>
  <p>This is how i save image to wwwroot/Products on server side</p>
  <pre><code>  [HttpPost]
      [Route(&quot;[action]&quot;)]
      public IActionResult AddProducts()
      {
          try
          {
  
              var files = Request.Form.Files;
              if (files != null &amp;&amp; files.Count &gt; 0)
              {
                  var product = JsonConvert.DeserializeObject&lt;Product&gt;(Request.Form[&quot;product&quot;]);
                  var images = new List&lt;Images&gt;();
                  var productSizeLink = JsonConvert.DeserializeObject&lt;List&lt;ProductSizeLink&gt;&gt;(Request.Form[&quot;size&quot;]);
                  var productColorLink = JsonConvert.DeserializeObject&lt;List&lt;ProductColorLink&gt;&gt;(Request.Form[&quot;colors&quot;]);
                  // var category = JsonConvert.DeserializeObject&lt;Category&gt;(Request.Form[&quot;category&quot;]);
                  // var indexImg=Convert.ToInt32(Request.Form[&quot;imgIndex&quot;]);
  
  
                  this.db.Product.Add(product);
                  foreach (var item in productSizeLink)
                  {
                      this.db.ProductSizeLink.Add(item);
                  }
                  foreach (var item in productColorLink)
                  {
                      this.db.ProductColorLink.Add(item);
                  }
  
                  string webRootPath = this._env.WebRootPath;
                  var folderName = &quot;Products&quot;;
                  string newPath = Path.Combine(webRootPath, folderName);
                  if (!Directory.Exists(newPath))
                  {
                      Directory.CreateDirectory(newPath);
                  }
                  var pathtodb = &quot;&quot;;
                  var i = 1;
                  foreach (var item in files)
                  {
                      if (item.Length &gt; 0)
                      {
                          string fileName = item.FileName;
                          var gid = Guid.NewGuid().ToString();
                          string fullPath = Path.Combine(newPath, gid + Path.GetExtension(fileName));
                          pathtodb = Path.Combine(folderName, gid + Path.GetExtension(fileName));
                          images.Add(new Images { ImageId = Guid.NewGuid(), ProductId = product.ProductId, Path = pathtodb, OrderBy = i++ });
                          using (var stream = new FileStream(fullPath, FileMode.Create))
                          {
                              item.CopyTo(stream);
                          }
                      }
  
                  }
                  foreach (var item2 in images)
                  {
                      Console.WriteLine(item2.ImageId + &quot; &lt;&lt;----------------------------&quot;);
                      this.db.Images.Add(item2);
  
                  }
  
                  this.db.SaveChanges();
  
                  return Ok(&quot;Product Added Successfully&quot;);
  
              }
  
              return Ok(&quot;No files found&quot;);
          }
  
          catch (Exception e)
          {
  
              return BadRequest(e.Message);
          }
  
  
          // return Ok(&quot;Done&quot;);
      }
  </code></pre>