Question

I am working on a project where it is needed to upload multiple files of different type.

I want to store the files in the database (I am not sure if this is the best idea also) as a nested model. May be called document.

I have following questions.

  1. Do I have to use a plugin / gem, I didn't find any simple implementation of it.

  2. If yes, what would be the best gem / plugin for that ? As far as I could fine out paperclip doesn't support storing in the database but attachment_fu does.

  3. Is it possible to do it with jQuery without refreshing the page ?

I would also like to handle some errors regarding filesize and types.

regards, Hardik

PS: I am using rails 2.3.5

Was it helpful?

Solution

first of all, never ever store files in the database!

If you save files in the database, you have to query it and go through the whole rails stack just to get the file. As you can imagine: this is slow. A webserver is much faster in delivering files and static content, because they are build to do so. If your site becomes bigger, it would be a good idea to put your static content somewhere else, like Amazon S3 or other asset hosts. If your files aren't in the database, they are independent and easily to move (the image_tag helper is then your best friend).

  1. Of course you don't have to use a plugin/gem. You can always implement everything on your own, but that's of course a bad idea, because others have invented this wheel already which saves you a lot of time.

  2. paperclip is still my choice, quite nice and in my opinion easier to handle than attachment_fu. It also has your requested validations.

  3. Sure, there is http://www.uploadify.com/ for example, allows multiple file uploads and the things you can imagine :)

Regards,

Alex

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top