c# - Saving Base64String in SQL Database results in NULL -


i trying save image database using following method

        public string imagetobase64(image image, imageformat format)     {         using (memorystream ms = new memorystream())         {             // convert image byte[]             image.save(ms, format);             byte[] imagebytes = ms.toarray();              // convert byte[] base64 string             string base64string = convert.tobase64string(imagebytes);             return base64string;         }     }  public image base64toimage(string base64string)     {         // convert base64 string byte[]         byte[] imagebytes = convert.frombase64string(base64string);         memorystream ms = new memorystream(imagebytes, 0, imagebytes.length);          // convert byte[] image         ms.write(imagebytes, 0, imagebytes.length);         image image = image.fromstream(ms, true);         return image;     } 

i saving follow object,

public class mediaimage {     [key]     public guid id { get; set; }     [column(typename = "varchar(max)")]     public string image { get; set; }     public string contenttype { get; set; } } 

when step through base64toimage working (i able copy/paste string image).

however when save mediaimage object database image field null though had value prior saving database.

as far can see there no exception being thrown. not sure if data type incorrect?

depending on size of images/version of mssql should select data type binary strings list ... https://msdn.microsoft.com/en-gb/library/ms187752.aspx

but! before ... read because storing images in db not best option ... https://stackoverflow.com/a/5613926/5040941


Comments