将图像文件插入MySql并在asp.net页面中检索这些文件... [英] insert image file in to MySql and retrive those in asp.net page...

查看:64
本文介绍了将图像文件插入MySql并在asp.net页面中检索这些文件...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传一个图像文件并将其保存到MySql数据库中...并在asp.net页中检索这些保存的图像..请给我完整的编码,使用MySql,C#,ASP.net ....

i want to upload an 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....

推荐答案


您可以从文件上传发布的文件属性中获取图像数据.在提交"按钮中单击事件...
Hi
You can get the image data from the file uploads posted file property. In the submit button click event...
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());



}



如代码中所示,将blob字符串保存到具有BLOB数据类型的mySql表列中.如代码中所示检索它,您可以获得字节流(如果需要,可以获取内存流,也可以将其转换为位图).您可能需要使用流来显示



as show in the code save the blob string to a mySql table column with BLOB data type. Retrive it as shown in the code, you can get a byte stream (memory stream if you want, and also possible to convert it in to bitmap). you may need to use the stream to display


我通常将这些类型建议放在注释"中,但是对于您的问题,这是一个答案.
你试过什么了?如果您研究过CodeProject本身,将会有100多个带有适当解释性答案的辅助线程.
现在是最让我烦恼的部分,即:"给我完整的编码".为什么您认为这个世界上该死的人应该由别人来做您的工作?而且,如果您想要完整烘焙的代码,则该地点称为 www.rentacoder.com [
I usually put these type suggestions in Comments but for your question this is an ANSWER.
What have you tried so far? If you would have looked into CodeProject itself, there would be 100s of smiliar threads with proper explained answers.
Now comes the part which irritates me most i.e.: ''Give me full coding''. Why the hell in the world do you think that some one else should do your work? And if you want FULL BAKED CODE, the place is called www.rentacoder.com[^]


希望
Hope this[^] link might give you an idea.

We are here to help you only. Not to do your Homework.


这篇关于将图像文件插入MySql并在asp.net页面中检索这些文件...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆