# Using attachment\_fu to store mp3

**URL:** <https://www.ruby-forum.com/t/using-attachment-fu-to-store-mp3/173654>\
**Category:** Rails\
**Created:** [August 12, 2009, 7:57pm UTC](https://www.ruby-forum.com/t/using-attachment-fu-to-store-mp3/173654 "2009-08-12T19:57:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![siddharth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f19dbf/32.png) [@siddharth](https://www.ruby-forum.com/u/siddharth)\
**Post date:** [August 12, 2009, 7:57pm UTC](https://www.ruby-forum.com/t/using-attachment-fu-to-store-mp3/173654/1 "2009-08-12T19:57:24Z")

</div>

Hi,

I am trying to store mp3 files using the attachment\_fu and I have  
managed to store it on the file system and the database as a blob. The  
problem is I dont know if saving it in the public folder of the file  
system is safe and when I store it as an longblob in the database how do  
i send it back to the user as something that can be downloaded.

I apologize if this sounds too silly as I am a newbie and trying to  
build an app which handles large amounts of mp3 files. I am also worried  
about security of storing the music files on the public folder.

I would appreciate any help on this .

Thank you

---

<div class="post-metadata">

**Author:** ![siddharth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f19dbf/32.png) [@siddharth](https://www.ruby-forum.com/u/siddharth)\
**Post date:** [August 13, 2009, 8:02pm UTC](https://www.ruby-forum.com/t/using-attachment-fu-to-store-mp3/173654/2 "2009-08-13T20:02:34Z")

</div>

You probably do not want to store the files in public. Store them  
somewhere else if you need to protect them with passwords.  
You can easily upload them to Amazon’s S3 with attachment\_fu, just be  
sure to set :s3\_access to an appropriate value  
And you can use send\_data with :disposition =\> ‘inline’ to send the  
data to the user. See

> **[ActionController::Streaming](https://api.rubyonrails.org/classes/ActionController/Streaming.html)**
>
> Allows views to be streamed back to the client as they are rendered. By default, Rails renders views by first rendering the template and then the layout.

On Aug 12, 10:57 am, Siddharth Ravichandran \<rails-mailing-

---

<div class="post-metadata">

**Author:** ![siddharth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f19dbf/32.png) [@siddharth](https://www.ruby-forum.com/u/siddharth)\
**Post date:** [August 13, 2009, 9:06pm UTC](https://www.ruby-forum.com/t/using-attachment-fu-to-store-mp3/173654/3 "2009-08-13T21:06:00Z")

</div>

hitch wrote:

> You probably do not want to store the files in public. Store them  
> somewhere else if you need to protect them with passwords.  
> You can easily upload them to Amazon’s S3 with attachment\_fu, just be  
> sure to set :s3\_access to an appropriate value  
> And you can use send\_data with :disposition =\> ‘inline’ to send the  
> data to the user. See  
> [ActionController::Streaming](http://api.rubyonrails.org/classes/ActionController/Streaming.html)
> 
> On Aug 12, 10:57ï¿½am, Siddharth Ravichandran \<rails-mailing-

Thank you for the response. I read on a few forums that storing it on  
the public file is better because it reduces databases access time which  
may eventually slow done the entire application. As I would be working  
with a lot of mp3 files is there anyway I can store them in folder that  
can be protected because Mysql does not handle the blob format very well  
and I am unable to get it retrieve it with the same quality.

Can mp3s be stored in mysql in any other way like binary format and  
retrieved without loss of quality.

Thank you again.

---

<div class="post-metadata">

**Author:** ![siddharth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f19dbf/32.png) [@siddharth](https://www.ruby-forum.com/u/siddharth)\
**Post date:** [August 13, 2009, 9:15pm UTC](https://www.ruby-forum.com/t/using-attachment-fu-to-store-mp3/173654/4 "2009-08-13T21:15:10Z")

</div>

On Aug 13, 3:06 pm, Siddharth Ravichandran \<rails-mailing-l…@andreas-  
[s.net](http://s.net)\> wrote:

> ## Thank you again.
> 
> Posted viahttp://www.ruby-forum.com/.

Slow down and think. You can store files in the local filesystem in  
places other than your Rails apps /public directory. hitch linked you  
to [ActionController::Streaming](http://api.rubyonrails.org/classes/ActionController/Streaming.html);  
send\_file is a good place to start. (Though in practice this just  
tends to be good at tieing up a specific Rails instance during the  
file sending process and you’ll eventually use something like  
mod\_xsendfile, but take one thing at a time!)

---

<div class="post-metadata">

**Author:** ![siddharth](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/f19dbf/32.png) [@siddharth](https://www.ruby-forum.com/u/siddharth)\
**Post date:** [August 13, 2009, 10:06pm UTC](https://www.ruby-forum.com/t/using-attachment-fu-to-store-mp3/173654/5 "2009-08-13T22:06:37Z")

</div>

pharrington wrote:

> On Aug 13, 3:06ï¿½pm, Siddharth Ravichandran \<rails-mailing-l…@andreas-  
> [s.net](http://s.net)\> wrote:
> 
> > ## Thank you again.
> > 
> > Posted viahttp://www.ruby-forum.com/.
> 
> Slow down and think. You can store files in the local filesystem in  
> places other than your Rails apps /public directory. hitch linked you  
> to [ActionController::Streaming](http://api.rubyonrails.org/classes/ActionController/Streaming.html);  
> send\_file is a good place to start. (Though in practice this just  
> tends to be good at tieing up a specific Rails instance during the  
> file sending process and you’ll eventually use something like  
> mod\_xsendfile, but take one thing at a time!)

Thank you very much. That was really helpful. I have decided to store  
the application on a different folder and I use send\_file to play the  
music.  
Thank you very much again.
