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.
- Using default rails methods to upload a file. Ex: http://www.tutorialspoint.com/ruby-on-rails/rails-file-uploading.htm
- Using a plugin like 'PaperClip'
Following are my concerns:
- I want to keep the file upload as simple as possible
- Keep as away as dependencies like Imagemagic etc
- I'm using rails 2.8.3
- concurrent file uploads can be happen by multiple users
please can someone tell me what are the pros and cons of having
- writin开发者_高级运维g a simple file upload (option 1)
- using a plugin/gem to upload a files
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.
精彩评论