Practical eCommerce

Developer’s Diary Blog Home · F.A.Q.'s

HOME · Saturday, July 5, 2008

Developer’s Diary

Handle File Uploads Easily in Rails

Recently I have been working with file uploads quote a bit in Ruby on Rails. In the past I have struggled through the process of allowing a user to upload a file (whether it be an image or a PDF file) from a web form. Let’s just say that this represents one of those occasions that I am glad to be using Ruby on Rails, due mainly to a nice little plugin called “attachment_fu” by Rick Olson. This is a file upload plugin that makes the process of uploading files from web forms almost trivial, and makes the uploading, resizing, and thumbnailing of uploaded images much, much easier.

Installation is as simple as typing:

script/plugin install http://svn.techno-weenie.net/projects/plugins/attachment_fu/

in the root directory of your Rails application. This will download the plugin from the repository and install it in your Rails application. One thing to remember is that it requires an image processor to be installed on the machine you are working with, and the web server that will be hosting your application. You can choose from ImageScience, RMagick or minimagick, and there is plenty of documentation out there to get these installed. Once you have the plugin installed, and the image processor installed, you are ready to upload files to your Rails applications.

For the most part, this plugin makes files uploads simple. You can easily set the type of file, such as PNG or PDF, that you want to allow to be uploaded. You can even validate file uploads based on the file size. Files can be stored on the filesystem, as binary data in a database, or on Amazon’s S3 storage service. Uploaded images can be resized easily based on an aspect ratio, and creating additional thumbnail images of smaller sizes is so simple it is mind-boggling. Needless to say that integrating file uploads into your forms is also made simple and elegant.

I’m not going to go into a tutorial on how to use the plugin, since the README file for attachment_fu is pretty comprehensive. However, I wanted to reflect as a developer on what a help plugins like this are. Rather than dealing with the technical aspects of how to securely upload images and other files, I can concentrate on how I want my application to work. My time is spent working out usability issues and interface ideas, which is a good thing.

Thanks to folks like Rick Olsen, I have a tool that let’s me concentrate on what is important, so keep an eye out for plugins that you might be able to develop to benefit others.

↑ Back to Top

Comments:

Greg Says:

Nice article. I often find myself ‘reinventing the wheel’. Sometimes I feel it’s useful to tread where others have gone before because I’ll do something differently or really learn how things work. But you make a great point about freeing up time to work on the critical parts of your own ap.

Aleksandr Says:

So basically you told us that attachment_fu exists? Nice


Leave a Comment:

Brian Getting

Brian Getting is the Online Director at Practical eCommerce, specializing in website design and application development.

Calendar

July 2008
S M T W T F S
« May    
 12345
6789101112
13141516171819
20212223242526
2728293031  

Categories

Browse blog posts by category.

RSS Content Feeds

Technorati Tags

Ecommerce Articles

Browse All Articles
Browse our complete archive of ecommerce articles.
Accounting, Management & Legal
Ecommerce articles related to managing a small business including ecommerce accounting, business strategy and legal considerations.
Conversion & Usability
Online business articles about converting web site visitors into customers and how to gauge and improve your business website's usability.
Development & Programming
Articles to help designers, developers and programmers create successful, search engine friendly ecommerce websites and improve existing ones.
Hosting, Infrastructure & Software
Articles for ecommerce businesses about ecommerce web hosting, business infrastructure, business strategy and helpful ecommerce & small business software.
Interviews & Profiles
Interviews with prominent ecommerce business personalities and profiles of successful online businesses.
Inventory & Shipping
Ecommerce articles about inventory management, ecommerce order fulfillment and product shipping considerations.
Marketing & Revenue Growth
Articles relating to online marketing, email marketing and using the Internet to growing your business.
Search Engine Optimization
Search engine optimization articles for ecommerce business owners, strategists, marketers and developers.
Shopping Carts & Online Payments
Articles covering ecommerce shopping cart platforms and options for choosing an online payment gateway.
Training & Education
Tutorials and articles providing training and education for ecommerce business owners and developers of ecommerce websites.

Search Articles

Ecommerce Community

Ecommerce Blogs
Read our blogs about ecommerce topics written by industry professionals.
Community Forum
Connect with other ecommerce professionals to trade advice and answers in our community forum.
Podcasts
Check out our ecommerce podcasts covering topics ranging from interviews to tutorials.
RSS Content Feeds
Subscribe to our RSS feeds and have fresh ecommerce content delivered to you.

Ecommerce Resources

Free Email Newsletter
Sign up for Ecommerce Notes, our free email newsletter for ecommerce business owners and developers.
Ecommerce Directory
Browse our directory of ecommerce products and services, or submit your own listing in our directory.
Ecommerce Glossary
Familiarize yourself with terminology or submit terms to help others with our Ecommerce Glossary.
Events Calendar
Find out about upcoming ecommerce events or invite other ecommerce professionals by posting your own event.
Press Releases
Browse ecommerce related press releases and post your own press release for distribution.
Ecommerce Store & Back Issues
Pick up back issues of Practical eCommerce magazine along with other merchandise from Practical Ecommerce

About Practical eCommerce

Frequently Asked Questions
Look at frequently asked questions regarded using our website, subscribing to our magazine and more.
Advertising Information
Information about advertising in Practical eCommerce magazine, on our website, or in our email newsletters.
Editorial Sharing
Learn about options for sharing our content with your visitors, customers or employees.
About Us
Learn more about Practical Ecommerce magazine and meet our staff.
Contact Us
Contact Practical Ecommerce at any time for more information. We'd love to hear from you.
AdvertisementEndiciaBDXIArial Software

Copyright 2007 Confluence Distribution, Inc. and Practical eCommerce.
All Rights Reserved.

Privacy PolicyConditions of UseContact Us