Solved

ms sql server - mp3 stored in database?

Posted on 2011-03-10
8
538 Views
Last Modified: 2012-05-11
Can mp3's be stored in sql database?
0
Comment
Question by:GlobaLevel
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 32

Expert Comment

by:Ephraim Wangoya
ID: 35097375
Any binary data can be stored in SQL Database

Just create a field of type VARBINARY(MAX)
0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 35097542
but can I use my asp.net web page to pull it from there to the client side..thanks
0
 
LVL 54

Expert Comment

by:Huseyin KAHRAMAN
ID: 35097687
i suggest put the files in a file system which is not visible/readable by users
and store the path/id of file sin table
then when users want to download it, you can open the file and send to browser by setting "content-type" and using "attachment"

storing files in db looks like a big headache :)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Author Comment

by:GlobaLevel
ID: 35098228
Hainkurt...thanks for the reply...great suggestion...would your method work in the situation...where we have short mp3..lasting 5 seconds in length and they need to be downloaded rapidly...its a user test to see if they recognize certain sounds...and the test occurs in a small window..so hopefully buffering wont be an issue..which I cant imagine ..as the mp3s are only 5 seconds in lenght...they will arrive at the client in succession...one after another...

you can open the file and send to browser by setting "content-type" and using "attachment"
>>not sure what you mean by this...
0
 
LVL 54

Expert Comment

by:Huseyin KAHRAMAN
ID: 35098430
5 sec mp3 will be like (1 min=1MB, 1000K/60s = 16KB/s) 80K
this is like 200x300 image file :) user will get it in seconds...

you write a page like getMp3.aspx?id=1234
when this is called it will connect to db, get all the details for that mp3file with id=1234
then read the file on server side, get the first 5 seconds (not a good idea :) random 5 sec from middle is better) and send the 5 sec mp3 file to user (you need some kind of libraries to create on time mp3 files) unless you prepare these samples per file and store permenantly on your server...

here is a code to read and send it to browser

Dim fs As FileStream = New FileStream(mp3Path, FileMode.Open, FileAccess.Read, FileShare.Read)
Dim br As New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(CInt(fs.Length))

Response.Clear()
Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", GetFileName(mp3Path)))
Response.ContentType = "audio/mpeg"
Response.BinaryWrite(bytes)
Response.Flush()

br.Close()
fs.Close()

Open in new window

0
 
LVL 54

Accepted Solution

by:
Huseyin KAHRAMAN earned 500 total points
ID: 35098500
in the code above, GetFileName is actually

System.IO.Path.GetFileName(mp3Path)

it will strip out the file name of full path

if mp3Path="c:\music\dance\atb\9pm.mp3", System.IO.Path.GetFileName(mp3Path) will give you "9pm.mp3"

this may be important when user tries to save it on his local machine... if you want browser not pop-up save dialog, remove attachement from above code

Response.AddHeader("content-disposition", String.Format("attachment; filename={0}", GetFileName(mp3Path)))
-->
Response.AddHeader("content-disposition", String.Format("filename={0}", GetFileName(mp3Path)))

if you use some ActiveX object to play mp3 file, just point the src of media file to getMp3.aspx?id=1234 and page will send 5 sec audio to the media player (dont use attachment in this case, or maybe it will be ignord by player, not sure)


0
 
LVL 10

Author Comment

by:GlobaLevel
ID: 35112614
HainKurt...you really hit the ball our of the park...I appreciate your expertise..little new on the media thing...a few questions..if you dont mind..

get the first 5 seconds (not a good idea :) random 5 sec from middle is better)
>>Not sure what you mean...

this may be important when user tries to save it on his local machine... if you want browser not pop-up save dialog, remove attachement from above code
>> dont want to save...as soon as the mp3 gets to the client browser..run and close/exit out as more will be on the way...and dont want to pile up mediaplayers on client..

0
 
LVL 54

Expert Comment

by:Huseyin KAHRAMAN
ID: 35286363
first 5 seconds is most of the time is just intro and people will not hear anything meaningful...
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question