I want to convert my image to base64string. I want to save the base64string to my database. I can get the path of my image. How can I get the image from my path and convert the image to base64string and what datatype do I need to put inorder to save base64string to my database is it BLOB?
try
{
var cafNo = entCafNo.Text;
var time = tpTime.Time;
await CrossMedia.Current.Initialize();
if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
{
await DisplayAlert("No Camera", "No Camera Available", "Ok");
return;
}
var file = await CrossMedia.Current.TakePhotoAsync(
new StoreCameraMediaOptions
{
SaveToAlbum = true,
Name = cafNo + "_IMG_01.jpg"
}
);
// provide read access to the file
FileStream fs = new FileStream(file.Path, FileMode.Open, FileAccess.Read);
// Create a byte array of file stream length
byte[] ImageData = new byte[fs.Length];
//Read block of bytes from stream into the byte array
fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length));
//Close the File Stream
fs.Close();
string _base64String = Convert.ToBase64String(ImageData);
entPhoto1Url.Text = _base64String;
}
catch(Exception ex)
{
await DisplayAlert("Error", ex.Message, "OK");
}