Click here to Skip to main content
15,891,316 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i insert image file into mysql but it takes null values....how to convert image to binary as wel as binary to image..to retrive image in aspx page..
Posted

try this[^]
 
Share this answer
 
Comments
shanthikalai 16-Feb-11 6:12am    
this also take null values...my question is i want to upload a image file and save that into MySql database...and retrive those saved images in asp.net page..please give me full coding,using MySql,C#,ASP.net....
MCY 16-Feb-11 6:56am    
I do not think anyone would give full coding.
Hi
In mysql table create a column with datatype Blob. Then in the form submiting event..
C#
protected void Button1_Click(object sender, EventArgs e)
 {
     HttpPostedFile postedFile=FileUpload1.PostedFile;
     Stream stream = postedFile.InputStream;
     BinaryReader bReader=new BinaryReader(stream);
     byte[] bytes=bReader.ReadBytes((int)stream.Length);

     //STORE THIS STRING IN THE BLOB COLUMN IN MYSQL
     string blob=Convert.ToBase64String(bytes);


     // For testing--- to show the image back to browser
     byte[] bytes1 = Convert.FromBase64String(blob);
     Response.ContentType = postedFile.ContentType;
     Response.OutputStream.Write(bytes1, 0, bytes1.Count());



 }

convert your posted file to a blob string as shown above and store in the database (you may need to store the content type as well in another column). Retrive from the database , convert the string to byte array. This byte array you may direct to output stream or handle in some way to display in a control. Hope this helps
 
Share this answer
 
Comments
shanthikalai 16-Feb-11 6:12am    
this also take null values...my question is i want to upload a image file and save that into MySql database...and retrive those saved images in asp.net page..please give me full coding,using MySql,C#,ASP.net....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900