# File upload --- acts\_as\_attachment or file\_column

**URL:** <https://www.ruby-forum.com/t/file-upload-acts-as-attachment-or-file-column/84991>\
**Category:** Rails\
**Created:** [February 9, 2007, 1:35am UTC](https://www.ruby-forum.com/t/file-upload-acts-as-attachment-or-file-column/84991 "2007-02-09T01:35:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![albert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@albert](https://www.ruby-forum.com/u/albert)\
**Post date:** [February 9, 2007, 1:35am UTC](https://www.ruby-forum.com/t/file-upload-acts-as-attachment-or-file-column/84991/1 "2007-02-09T01:35:17Z")

</div>

Hi,

I have a simple rubyonrails application, in which users can submit their  
research projcts. The applcation has the following models:

project: set of predefined fields where users save their project in  
member\_project: keep track of who submitted what project  
member: keep track of members.

I need to provide file uploading facilities with this application so the  
users can attach files to their projects. The system should support:  
pdf, txt, ps, word : maximum 700 kb  
jpg, gif: maximum of 1 MB  
Mov, Mpeg, Mpg, and AVI: maximum size of 1.9 MB

I wonder which of acts\_as\_attachment or file\_column are more appropriate  
for my application.alos, whether I should save my files in the database  
or on the server (considering that I don’t know about Network  
Adminstration and don’t know whether I should get some type of write  
permission for my APP to be able to do this).

Any suggestion and help is greatly appreciated.

Thanks,  
Albert

P.S. Is there any open-source application that I can look at to get an  
idea of how to do this?

---

<div class="post-metadata">

**Author:** ![albert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@albert](https://www.ruby-forum.com/u/albert)\
**Post date:** [February 9, 2007, 2:15am UTC](https://www.ruby-forum.com/t/file-upload-acts-as-attachment-or-file-column/84991/2 "2007-02-09T02:15:06Z")

</div>

Hi Albert,  
My recommendation would be that you not store your files in the  
database if at all possible. Databases are inefficient and clumsy at  
storing files like the ones you’re dealing with. Surely your host gives  
you write permissions to your own application folder, because how else  
would you deploy your code, add to logs, etc.

As for acts\_as\_attachment vs. file\_column, sorry can’t help you  
there. I found them both too clumsy and switched to just writing the  
code myself. We’re only talking about 10 lines of code, max, for most  
situations here, so it’s not really a big saving.

albert wrote:

> Hi,
> 
> I have a simple rubyonrails application, in which users can submit their  
> research projcts. The applcation has the following models:
> 
> project: set of predefined fields where users save their project in  
> member\_project: keep track of who submitted what project  
> member: keep track of members.
> 
> I need to provide file uploading facilities with this application so the  
> users can attach files to their projects. The system should support:  
> pdf, txt, ps, word : maximum 700 kb  
> jpg, gif: maximum of 1 MB  
> Mov, Mpeg, Mpg, and AVI: maximum size of 1.9 MB
> 
> I wonder which of acts\_as\_attachment or file\_column are more appropriate  
> for my application.alos, whether I should save my files in the database  
> or on the server (considering that I don’t know about Network  
> Adminstration and don’t know whether I should get some type of write  
> permission for my APP to be able to do this).
> 
> Any suggestion and help is greatly appreciated.
> 
> Thanks,  
> Albert
> 
> P.S. Is there any open-source application that I can look at to get an  
> idea of how to do this?

---

<div class="post-metadata">

**Author:** ![albert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@albert](https://www.ruby-forum.com/u/albert)\
**Post date:** [February 9, 2007, 2:46am UTC](https://www.ruby-forum.com/t/file-upload-acts-as-attachment-or-file-column/84991/3 "2007-02-09T02:46:38Z")

</div>

I agree that it’s better to write your own. In an app I’m writing I’ve  
used acts\_as\_attachment. It has some convenient thumbnail methods for  
images but it also does some things I don’t like: 1) separate subdirs  
for every set of files which are not cleaned up if file is destroyed and  
2) keeps original filenames.

I can change this behavior in the code but I don’t know if that is more  
trouble than just writing file handling myself.

---

<div class="post-metadata">

**Author:** ![albert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@albert](https://www.ruby-forum.com/u/albert)\
**Post date:** [February 9, 2007, 5:38am UTC](https://www.ruby-forum.com/t/file-upload-acts-as-attachment-or-file-column/84991/4 "2007-02-09T05:38:50Z")

</div>

I’ve been pondering this issue for some time now. Keeping files on  
the file system is OK, but what if you need to run multiple rail  
servers? The file system then needs to be a network file system  
accessible by all of the rails servers. This was the whole rational  
for storing the sessions in the database.

I looked at ferret for full text search and had this same issue. The  
indexes are stored in a directory under rails root called indexes.  
Looking at all the simultaneous access issues around ferret already  
putting those indices on a network share sounds even scarier.

Is it more painful to use a shared file system or just shove the stuff  
in the DB? Is storing blobs in the DB really that bad or is that one  
of those urban legends out there?

For the research paper idea, I would just shove that baby into the  
database and put a fulltext index on it! (I know I’ll be eating these  
words later).

Mike Vargo

---

<div class="post-metadata">

**Author:** ![albert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@albert](https://www.ruby-forum.com/u/albert)\
**Post date:** [February 9, 2007, 2:52am UTC](https://www.ruby-forum.com/t/file-upload-acts-as-attachment-or-file-column/84991/5 "2007-02-09T02:52:41Z")

</div>

Thanks a lot for your replies.  
I would appreciated if you can direct me to some references as how to  
write the uploading code by myself since I am new to ROR and don’t have  
any idea as how to handel the different file-types, limit the upload  
size, or how to store the files in anywhere else than the database.

Many thanks,  
-Albert

Carl J. wrote:

> I agree that it’s better to write your own. In an app I’m writing I’ve  
> used acts\_as\_attachment. It has some convenient thumbnail methods for  
> images but it also does some things I don’t like: 1) separate subdirs  
> for every set of files which are not cleaned up if file is destroyed and  
> 2) keeps original filenames.
> 
> I can change this behavior in the code but I don’t know if that is more  
> trouble than just writing file handling myself.

---

<div class="post-metadata">

**Author:** ![albert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/48db29/32.png) [@albert](https://www.ruby-forum.com/u/albert)\
**Post date:** [February 9, 2007, 7:20am UTC](https://www.ruby-forum.com/t/file-upload-acts-as-attachment-or-file-column/84991/6 "2007-02-09T07:20:57Z")

</div>

On 2/8/07, Carl J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I agree that it’s better to write your own. In an app I’m writing I’ve  
> used acts\_as\_attachment. It has some convenient thumbnail methods for  
> images but it also does some things I don’t like: 1) separate subdirs  
> for every set of files which are not cleaned up if file is destroyed and  
> 2) keeps original filenames.
> 
> I can change this behavior in the code but I don’t know if that is more  
> trouble than just writing file handling myself.

1. patches welcome 🙂
2. I just make the mods in the model. If I want a custom file naming  
scheme, I typically override #full\_filename.

It is easy to write your own, but after awhile you start running into  
the same problems over and over again. Thats why I wrote  
acts\_as\_attachment.

Well, I also wrote it to store files in the db (which file\_column  
doesn’t do). It didn’t take long before I added file system support,  
which is what I primarily use now.

–  
Rick O.  
[http://weblog.techno-weenie.net](http://weblog.techno-weenie.net)  
[http://mephistoblog.com](http://mephistoblog.com)
