File upload --- acts_as_attachment or file_column

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?

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?

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.

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

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.

On 2/8/07, Carl J. [email protected] 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 :slight_smile:
  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://mephistoblog.com