-1
I have never worked with anything like this and would like to insert an image into a database and for what I saw the best way is to transform an image into a string, I have searched and found some ways but I was blocked. And the only way I have to store images is in a folder outside the database, but then as I intend to do a gallery has no way to filter the images through Cartype.
public ActionResult Insert(Cars cars, HttpPostedFileBase photo)
{
string directory = @"~\Images";
if (ModelState.IsValid)
{
int recordsCreated = CreateCar(
cars.Brand,
cars.Model,
cars.CarType,
cars.PlateDate,
cars.Image);
}
if (photo != null && photo.ContentLength > 0)
{
var fileName = Path.GetFileName(photo.FileName);
photo.SaveAs(Path.Combine(directory, fileName));
return RedirectToAction("../Rent/Gallery");
}
return View();
}
Talk buddy, all right? Welcome to SOPT! When asking a question here on the site, prefer to post your code instead of making the images available. This way we can help you more efficiently and your question will be evaluated more positively. Refactor your question by placing your codes and just leave the images of the screens if it’s really relevant to the question, okay? Hug!
– Pedro Paulo
Use a
MemoryStream
to create abyte[]
from the image and then save thisbyte[]
in the database as a blob.– Augusto Vasques