I am doing a school project where i need to work with blob images with ef core.
I can query blob and convert to wpf BitmapImage, but when I want to reverse the process and I want to upload a selected image to the table I get into barrier.
So when I try to insert a 6.9kB picture to the table it is working great, but if I try a bit larger ~12kB it is not work.
I have a table called Products with the following columns: [Id],[Brand],[Name],[Image], ... other fields
This is my insert command:
...
OpenFileDialog ofd = new OpenFileDialog();
using(var ctx = new Context())
{
Product newProduct = new Product()
{
ProductId = Guid.NewGuid().ToString(),
Brand = ...,
Name = ...,
Image = File.ReadAllBytes(ofd.FileName),
};
ctx.Products.Add(newProduct);
ctx.SaveChanges();
}
This is Product model class:
// It is longblob in mysql
modelBuilder.Entity<Product>(entity =>
{
entity.ForMySQLHasCollation("utf8_hungarian_ci");
entity.Property(x=>x.Image).HasMaxLength(64 * 1024 * 1024); //I want max 64Mb
});
Please give me directions.
- I changed
max_allowed_packet=64Mb
in mysql - Changed the size of Image column
- I tried 3 way to make byte[] from image