public async Task <IActionResult> PutPlantImage(int id, imagePlant iPlant) { //Update the image of a plant var plant = _context.Plants.Where(p => p.PlantID == id).FirstOrDefault(); if (plant == null || iPlant == null) { return(BadRequest()); } //Convert the base64 string to bytes that can be stored on the database byte[] byteImage = Convert.FromBase64String(iPlant.image); plant.Image = byteImage; await _context.SaveChangesAsync(); return(Ok()); }
public async Task <ActionResult <imagePlant> > GetPlantImage(int id) { //Get the image of a plant based on its id var plant = await _context.Plants.Where(p => p.PlantID == id).FirstOrDefaultAsync(); if (plant == null) { return(NotFound()); } //Convert the image from the database to a base64 string imagePlant rPlant = new imagePlant() { id = id, image = Convert.ToBase64String(plant.Image) }; return(rPlant); }