title: What are the best practices to validate Image and upload in ASP.Net Core/EF Core?
body: <p>I have found some questions like <a href="https://stackoverflow.com/questions/42282205/validate-image-type-for-iformfile-in-asp-net-core">Validate Image Type</a> but it didn't fulfill my needs.<br>
  I have Model class named <code>Movie</code> which contains property  </p>
  
  <p><code>public byte[] Image { get; set; }</code> </p>
  
  <p>My <strong>View contains</strong> </p>
  
  <pre><code>&lt;form asp-action="Index" method="post" enctype="multipart/form-data"&gt;
    &lt;input asp-for="Image" type="file" id="files" class="form-control" /&gt;
    &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>and in controller, I am converting it to <strong>bytes</strong> and storing it in database. I want to validate it like, Files allowed <strong>.jpg</strong>, <strong>.jpeg</strong>, <strong>.png</strong> and max size of file <strong>5Mb</strong>.  </p>
  
  <pre><code>[HttpPost]
      public async Task&lt;IActionResult&gt; Index(Movie Movie, List&lt;IFormFile&gt; Image)
      {
          foreach(var item in Image)
          {
              if (item.Length &gt; 0)
              {
                  using (var stream = new MemoryStream())
                  {
                      await item.CopyToAsync(stream);
                      Movie.Image = stream.ToArray();
                  }
              }
          }
          _applicationDbContext.Movie.Add(Movie);
          _applicationDbContext.SaveChanges();
          return View();
      }
  </code></pre>
  
  <p>How can I validate the uploaded file ?</p>