_This is a modified version of EasySwUpload. I added several things for my own use (like the jsProgressBarHandler 0.3.3 - by Bramus) and fixed some issues that I came across. Please have a look at the original version from ‘over’ github.com/over/easy_swf_upload which may fit your needs better._
Joris.
¶ ↑
EasySwfUploadThis plugin will help you to embed swf upload into your project
First, install this plugin (my modified fork, or over’s original version):
script/plugin install git://github.com/trooster/easy_swf_upload.git or script/plugin install git://github.com/over/easy_swf_upload.git #script/generate easy_swf_upload is called for you automatically
¶ ↑
ExampleIn your application.html.erb include javascripts:
<%= javascript_include_tag :defaults, :swf_upload %>
Or on a specific page (assuming the prototype libraries are loaded in your application template):
<% content_for :javascript do %>
<%= javascript_include_tag :swf_upload %>
<% end %>
The Plugin does not works without the prototype javascript library.
Then, use this helper to embed swf upload to your application:
<%= swf_upload_area :url => upload_image_block_path, :filetypes => "*.jpg; *.gif", :button_text => "Upload", :button_style => "font-family: Arial, sans-serif; font-size: 14pt; font-weight:bold;" %>
If you want to allow uploading of only a single file, you can pass :single_file => true option to swf_upload_area helper.
If you want a file size limit use the file_size_limit option, for example :file_size_limit => “2 MB”. The default file size limit = 40 MB.
Another example with a button image, and single file upload:
<%= swf_upload_area :url => upload_image_block_path, :filetypes => "*.jpg; *.gif", :single_file => true, :file_size_limit => "100 MB" :button_image_url => "../images/XPButtonUploadText_61x22.png", :button_width => 61, :button_height => 22 %>
In your controller:
class PagesController < ApplicationController
# If your rails version < 2.3.0, go this way
session :cookie_only => false, :only => :upload_image_block # this is very important, don't forget to set it to false def upload_image_block @image_block = ImageBlock.new(:file => swf_upload_data) # here you can use your favourite plugin to work with attachments # use RJS here # render :action => "upload_image_block.js.rjs" render :update do |page| page['blocks'].insert("<div><img src="http://domain.com" /></div>") end end end
Also, you need to customize uploading area, for example:
<style> .uploadContainer { margin: 0; padding: 0; } .uploadContainer li { list-style: none; margin: 0; padding: 0; height: 2em; padding: 0.4em; border: #ccc; margin-bottom: 1em; } .uploadContainer li h6 { margin: 0; padding: 0; color: #000; font-size: 1.1em; } </style>
Uploading file template:
<li id="#{id}"><h6>#{title}</h6><span id="#{id}_progress">[ Loading Progress Bar ]</span></li>
– Copyright © 2008 Mikhail Tabunov, released under the MIT license See commit history on github for changes by others