sameera207
sameera207

Reputation: 16629

uploading a file with rail - what is the best approach

I have a requirement of uploading a file to my disk through my webpage. Seems like I have two options

My requirement is specific that I will upload ONLY text files.

  1. Using default rails methods to upload a file.
    Ex: http://www.tutorialspoint.com/ruby-on-rails/rails-file-uploading.htm
  2. Using a plugin like 'PaperClip'

Following are my concerns:

  1. I want to keep the file upload as simple as possible
  2. Keep as away as dependencies like Imagemagic etc
  3. I'm using rails 2.8.3
  4. concurrent file uploads can be happen by multiple users

please can someone tell me what are the pros and cons of having

Upvotes: 3

Views: 715

Answers (1)

Blake Simpson
Blake Simpson

Reputation: 1088

Writing your own file uploader is an option, but using a pre-built gem provides you with all of the code you need, straight after install.

Gems will usually have all of the functionality packaged into them that handles all of the cross-platform issues and security headaches your likely to run into by writing something from scratch. A well maintained gem will also have a good community behind it, keeping things up to date.

The popular Gems out there are really easy to use, and unless you are resizing images etc, you shouldn't need ImageMagick installed. Have a look at these:

http://railscasts.com/episodes/134-paperclip

https://github.com/technoweenie/attachment_fu/wiki

Paperclip is far easier to build a simple upload form with, but I'm not sure if it works on Rails 2. Attachment_fu is an old favorite from the Rails 2 days and will definitely be able to handle your problem, it just requires a little more configuration.

Upvotes: 4

Related Questions