I want that in my application I can select an image and it is saved in my sql server database, I was told that for this I had to convert it to base 64, I am using a web service that creates ASP.Net in c #, How do I store my image in my database?
I want that in my application I can select an image and it is saved in my sql server database, I was told that for this I had to convert it to base 64, I am using a web service that creates ASP.Net in c #, How do I store my image in my database?
The first thing you should have is a variable that accepts giant strings in your database like the BLOB (Binary Large Objects - in English), I work with one like this:
[imagen] varbinary(max) NULL,
This is clear when creating your database.
Now your code in C#
to extract would be something like this:
string base64String="";
using (Image imagen = Image.FromFile("la path de tu imagen"))
{
using (MemoryStream m = new MemoryStream())
{
imagen.Save(m, imagen.RawFormat);
byte[] Bytes = m.ToArray();
base64String = Convert.ToBase64String(Bytes);
}
}
And then after that you store base64String
like any other data