none
How better save image to database RRS feed

  • Question

  • Hi, i have one question, how can i better save image to database ? 1) save to folder and then to database 2) convert to byte 3) or another way ?
    Wednesday, August 17, 2011 8:33 AM

Answers

  • Hello

    if you are using entity framework i suggest you to save it as byte[]

    Here an example how i put a upload into the database:

     

     public ActionResult UploadSmallLogo(ClientWeb client, HttpPostedFileBase file)
        {
          if (file != null)
          {
            using (var reader = new BinaryReader(file.InputStream))
            {
              client.SmallLogo = reader.ReadBytes(file.ContentLength);
            }
    
            _clientService.Update(client, null);
          }
    
          return RedirectToAction("Edit", new { client.Id });
    
    }
    

    The small logo is just a byte array of the ef entity: public byte[] SmallLogo { get; set; }

     

    greets

    holger

    • Marked as answer by ClientID Wednesday, August 17, 2011 9:34 AM
    Wednesday, August 17, 2011 9:16 AM