user755230
user755230

Reputation: 125

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();

     MySqlCommand cmd1 = new MySqlCommand(getSQL1, objMyCon1);
     cmd1.ExecuteNonQuery();
     objMyCon1.Close();
     dbLoad();
}

Upvotes: 0

Views: 2043

Answers (3)

Sibghat Ullah
Sibghat Ullah

Reputation: 43

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...

Upvotes: 0

BreakHead
BreakHead

Reputation: 10672

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

Upvotes: 0

John
John

Reputation: 1296

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

Upvotes: 1

Related Questions