Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store an MP3 file in a a database?

Being new to storing data types in a database, I brought myself upon a problem whereas I need to store a media file inside some sort of database. I currently utilize MySQL. Since SO is a community which includes but is not limited to professional programmers, and one of the most high quality question and answer sites(as it pertains to programming), this question may have a fairly simple answer.

That being said, Someone explain to me how to store an abundance of media files inside an SQL database.

Please & Thank you to the stackoverflow.com community.

like image 375
user660943 Avatar asked Apr 20 '11 00:04

user660943


People also ask

Can we store MP3 file in database?

The typical pattern to follow when doing something like this is to save the MP3 (or any binary file) on the server in a particular directory, and save the path to the file in the database.

Can you store MP3 in MySQL database?

MySQL is fully capable of storing the full MP3 file as a BLOB, but can suffer some performance problems along the way. This part is an opinion based question -- there's no universal "right way", but most people I know would store the file on disk and only the path in the database.

How is data stored for MP3 files?

Inside an MP3 file, music is stored as long strings of bits (binary numbers, zeros and ones) in a series of chunks called frames. Each frame starts with a short header (a kind of table of contents), followed by the music data itself.


1 Answers

To store the actual mp3 you need to store it as a blob. A common alternative is to just store a file path. I personally prefer the second approach if possible as they are a lot easier to work with when it comes to refactoring/deploying/testing

like image 93
vickirk Avatar answered Sep 29 '22 07:09

vickirk