I'm using an ASP.NET MVC project. I'm trying to pass URL image to controller and want to save the image into database - not the image URL.
Asked
Active
Viewed 645 times
-2
-
And exactly what is your question? What have you done so far? – Hursey Sep 16 '19 at 00:31
2 Answers
0
Maybe you can download the image from the url and convert that to byte array , as you can see here.
After that you save the byteArray in your database.
If you want to read the image you can encode the bytes in base64 and send to the view.
return "image/jpeg;base64," + Convert.ToBase64String(bytes);
-1
In case of you have used HttpPostedFileBase object to get an image, then you should convert Image to byte Array and then you need to save that array to database rather than save URL directly.
You can see below code for the same.
public byte[] ConvertImageToByte(HttpPostedFileBase file)
{
byte[] imageByte = null;
BinaryReader rdr = new BinaryReader(file.InputStream);
imageByte = rdr.ReadBytes((int)file.ContentLength);
return imageByte;
}

ankitkanojia
- 3,072
- 4
- 22
- 35