I would like to create a data editing page for an animal object in my project written in C# MVC Core. I want to overwrite input type="file" tag with image stored in the database. Here is a class for animal. Properties for the photo is: ImageData, FileName, ContentType.
public class Animal
{
public Guid Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Sex { get; set; }
public int Age { get; set; }
public string Breed { get; set; }
public DateTime DateOfPost { get; set; }
public Guid UserId { get; set; }
public byte[] ImageData { get; set; }
public string FileName { get; set; }
public string ContentType { get; set; }
public virtual User User { get; set; }
}
}
I want to do this by using Blob in javascript. Here is my code in view:
<script>
const blob = new Blob([@Animal.ImageData], { type: '@Animal.ContentType' });
const file = new File([blob], '@Animal.FileName', { type: '@Animal.ContentType ' });
document.querySelector('input[type="file"]').files = file;
</script>
I am getting that error in my browser (https://i.stack.imgur.com/EhsKT.png) (https://i.stack.imgur.com/P8bnj.png)
I tried to resovle this problem with System.Linq.Enumerable.AsEnumerable ans also with System.Linq.Enumerable.ToArray but every time i get same error. Does anyone know how to fix this?