views:

115

answers:

3

Are there any gems / plugins that allow for a slick implementation? Bonus for allowing multiple uploads =)

A: 

I use the YUI uploader. Industrial strength, large community, book etc. I had to roll my own integration into Rails, but wasn't hard.

PS, check out the widget's examples, listed on the far right side of the page.

Larry K
+1  A: 

The generic mechanism for uploading is to encode the entirety of the file to be uploaded within the HTTP request entity. Therefore, by the time the server-side application even sees the request, the file has already been uploaded (although some servers permit the optimization that the server-side processing can begin before the entirety of the HTTP request has been transmitted to the server, but will block if the application needs data from the HTTP request that has not yet been received).

There are several Flash-based uploaders that permit uploading files in separate HTTP requests; they require that the server application have a separate endpoint accepting HTTP requests particular to uploading files. Some even implement progress bars, multiple file uploads, client-side constraints on content-type and content-length, and more besides. At random: YUI Uploader, Uploadify, FancyUpload.

Justice
+1  A: 

I used Uploadify which is written as a jQuery plugin, as the multi-file uploader for my blogging app called "Rehash" (source code), check the ProjectsController#new_upload action. We have used this on a few projects and keep improving our implementation. The tricky part with any Flash multi-file uploader (like Uploadify or FancyUpload) is dealing with Rails' cross-site request forgery protection and cookies. You want to ensure the request comes from the application and you may want to authenticate the upload. In Rehash I only allow the site administrator to upload for example, so I need to check both the session key and the authentication token. John Nunemaker has a nice blog post on Rails Tips on getting Uploadify set up, outlining the current best practice of dealing with the Flash/session stuff as Rack middleware, using Paperclip for file uploads, which is our same setup. In the end you have a nice multi-file uploader with style-able progress bars, but it is a good amount of work initially.

Uploadify has a sizeLimit option as well, check the docs.

Andy Atkinson