# Best way to store binary data

**URL:** <https://www.ruby-forum.com/t/best-way-to-store-binary-data/88265>\
**Category:** Rails\
**Created:** [March 9, 2007, 9:20am UTC](https://www.ruby-forum.com/t/best-way-to-store-binary-data/88265 "2007-03-09T09:20:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![amrkamel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@amrkamel](https://www.ruby-forum.com/u/amrkamel)\
**Post date:** [March 9, 2007, 9:20am UTC](https://www.ruby-forum.com/t/best-way-to-store-binary-data/88265/1 "2007-03-09T09:20:19Z")

</div>

Dear all,  
can any one tell me what is the best way to store binary data “e.g.  
images, videos …etc” of various sizes in a ROR application? should I  
store them in mysql database or in file system?  
Thanks alot 🙂 in advance…

Amr M. Kamel

---

<div class="post-metadata">

**Author:** ![amrkamel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@amrkamel](https://www.ruby-forum.com/u/amrkamel)\
**Post date:** [March 9, 2007, 9:57am UTC](https://www.ruby-forum.com/t/best-way-to-store-binary-data/88265/2 "2007-03-09T09:57:22Z")

</div>

Thanks alot for your very fast reply, and for database volume we can  
always solve it by adding extra hard disks and maybe use one of RAID  
technologies 🙂  
Thanks again.

---

<div class="post-metadata">

**Author:** ![amrkamel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@amrkamel](https://www.ruby-forum.com/u/amrkamel)\
**Post date:** [March 9, 2007, 10:45am UTC](https://www.ruby-forum.com/t/best-way-to-store-binary-data/88265/3 "2007-03-09T10:45:29Z")

</div>

On 9 Mar, 09:29, “mohan” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> U can store the binary data in mysql database. i think it is a best  
> way(suppose u have lak of lak image db volume will be huge, but i  
> think thats not big problem).

it’s a way, but it isn’t the best.  
databases will grow in size, creating problems for portability, backup  
dumps and speed.  
if you have a small amount of data storing binary data in database  
seems a good idea, for every other thing fs is the way to go, at least  
for me.

---

<div class="post-metadata">

**Author:** ![amrkamel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@amrkamel](https://www.ruby-forum.com/u/amrkamel)\
**Post date:** [March 9, 2007, 9:30am UTC](https://www.ruby-forum.com/t/best-way-to-store-binary-data/88265/4 "2007-03-09T09:30:19Z")

</div>

U can store the binary data in mysql database. i think it is a best  
way(suppose u have lak of lak image db volume will be huge, but i  
think thats not big problem).

Mohan

---

<div class="post-metadata">

**Author:** ![amrkamel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@amrkamel](https://www.ruby-forum.com/u/amrkamel)\
**Post date:** [March 11, 2007, 3:17pm UTC](https://www.ruby-forum.com/t/best-way-to-store-binary-data/88265/5 "2007-03-11T15:17:51Z")

</div>

That’s one way. Another is to setup some convention whereby you can  
calculate the file location based on the record ID or some other  
signifying data point in your model. This’ll make it easier to scale  
if you need to in the future.

---

<div class="post-metadata">

**Author:** ![amrkamel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@amrkamel](https://www.ruby-forum.com/u/amrkamel)\
**Post date:** [March 11, 2007, 3:52pm UTC](https://www.ruby-forum.com/t/best-way-to-store-binary-data/88265/6 "2007-03-11T15:52:53Z")

</div>

Dear Eleo,  
thanks for your fast reply but can you elaborate more “if this doesnt  
bother you, I am a NOOB :)”?  
thanks agin.

---

<div class="post-metadata">

**Author:** ![amrkamel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@amrkamel](https://www.ruby-forum.com/u/amrkamel)\
**Post date:** [March 9, 2007, 10:57am UTC](https://www.ruby-forum.com/t/best-way-to-store-binary-data/88265/7 "2007-03-09T10:57:30Z")

</div>

I don’t think it is a good idea. I can’t think it would be any better  
than saving the actual files. Having to pull images out of the  
database will probably add dramatically to database bandwidth over  
time.

Probably the only advantage is that saving to database is probably  
easier to do; requires less code.

I personally choose to save the actual files to the file system and  
store info about the file (width, height, filesize, md5, etc) to  
database.

---

<div class="post-metadata">

**Author:** ![amrkamel](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/df705f/32.png) [@amrkamel](https://www.ruby-forum.com/u/amrkamel)\
**Post date:** [March 11, 2007, 2:24pm UTC](https://www.ruby-forum.com/t/best-way-to-store-binary-data/88265/8 "2007-03-11T14:24:43Z")

</div>

Thank you all for your help :),  
Eleo, I like your idea but I should add also a column that stores file  
location on the file system “as a pointer” to be able to fetch the  
file? is this correct? or if there is a better approach plz let me  
know it…  
Thanks alot.
