开发者

how to save image,audio,video files to database as link?

i m not getting how to store a file to database so that at time application is uploaded to webserver user can download that file. till now i was just saving the file name to database and it is wrong.so do i need to save the link to database? i m getting confused?any suggession? till now i m using this code to store file in database,

protected void dbInsert(string fileType,string fileName,string fileExt)
{
     String getSQL1 = "INSERT into tbluploadedfilesdetail (FileDownloaded,FileType,FileName,FileExt) VALUES ("+0+",'"+fileType+"','"+fileName+"','"+fileExt+"');";

     MySqlConnection objMyCon1 = new MySqlConnection(strProvider);
     objMyCon1.Open();

    开发者_JAVA技巧 MySqlCommand cmd1 = new MySqlCommand(getSQL1, objMyCon1);
     cmd1.ExecuteNonQuery();
     objMyCon1.Close();
     dbLoad();
}


All you are doing here is saving the filename to the server, not the actual file. If you want to save a file to a database then the database field type needs to be binary. There are a lot of tutorials online to show you how. See http://www.codeproject.com/KB/aspnet/fileupload.aspx

For MySql you should use BLOB type or it's alternatives. Check out http://www.abbeyworkshop.com/howto/lamp/my_fieldtypes/index.html


Why don't you read bytes from files and write it to database you have to take Image as data type in data base.


Try storing the complete name with the path of the file too.. i had similer issue and i solved it by storing the complete path with name of file...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜