uploader 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +12 -15
- data/VERSION +1 -1
- data/app/controllers/uploader/uploads_controller.rb +2 -2
- data/app/helpers/uploader_helper.rb +4 -2
- data/lib/active_record/acts/uploader_upload.rb +32 -3
- data/test/rails_root/test/unit/upload_test.rb +10 -0
- data/uploader.gemspec +2 -2
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
= Uploader
|
2
2
|
|
3
|
-
Uploader makes it easy to integrate multiple file uploads into your application using SWFUpload
|
3
|
+
Uploader makes it easy to integrate multiple file uploads into your application using Uploadify or SWFUpload
|
4
4
|
|
5
5
|
== ----NOTES----
|
6
|
-
SWFUpload hasn't been updated in a while
|
7
|
-
Version 0.2.8 will be the last version to use swfupload.
|
8
|
-
|
9
|
-
We are currently working on a new upload gem that will use pupload
|
6
|
+
SWFUpload hasn't been updated in a while and tends to be buggy. We have added uploadify. We recommend using that instead.
|
10
7
|
|
11
8
|
== Installation
|
12
9
|
|
@@ -28,12 +25,9 @@ http://jquery.com/
|
|
28
25
|
|
29
26
|
Then include it in your layout:
|
30
27
|
<%= javascript_include_tag 'jquery/jquery.js' %>
|
31
|
-
|
32
|
-
Another option is to use jRails
|
33
|
-
http://ennerchi.com/projects/jrails
|
34
28
|
|
35
29
|
=== Create a model for uploads.
|
36
|
-
|
30
|
+
Create an 'Upload' model in upload.rb. acts_as_uploader accepts all valid options for paperclip via :has_attached_file => {}
|
37
31
|
|
38
32
|
class Upload < ActiveRecord::Base
|
39
33
|
|
@@ -113,7 +107,7 @@ default functionality that you may consider overriding.
|
|
113
107
|
Be sure to modify your routes file. Add the following line to ensure that your application uses the new uploads
|
114
108
|
controller instead of directly using the one inside the gem:
|
115
109
|
|
116
|
-
map.resources :uploads, :collection => { :
|
110
|
+
map.resources :uploads, :collection => { :multiupload => :post }
|
117
111
|
|
118
112
|
|
119
113
|
class UploadsController < Uploader::UploadsController
|
@@ -171,8 +165,14 @@ You'll need something like this in your layout so that uploader can add in the r
|
|
171
165
|
<%= yield :head -%>
|
172
166
|
|
173
167
|
Then to add an upload form:
|
168
|
+
|
169
|
+
SWFUpload version:
|
174
170
|
<%= upload_form(parent_object) %>
|
175
|
-
|
171
|
+
|
172
|
+
Uploadify version (recommended):
|
173
|
+
<%= uploadify_form(parent_object) %>
|
174
|
+
|
175
|
+
See the uploader_helper.rb file for options. parent_object should be the object which owns the uploads. ie a user, photo_album, etc.
|
176
176
|
|
177
177
|
=== Rake Tasks
|
178
178
|
|
@@ -304,12 +304,9 @@ Say you have chosen to display your upload in a table. Your code might look lik
|
|
304
304
|
|
305
305
|
I put the following in my main upload view
|
306
306
|
<% content_for :javascript do -%>
|
307
|
-
|
308
307
|
setup_submit_delete();
|
309
|
-
|
310
308
|
function upload_completed_callback(data){
|
311
309
|
jQuery('#upload-list').prepend(data);
|
312
|
-
setup_submit_delete();
|
313
310
|
}
|
314
311
|
<% end -%>
|
315
312
|
|
@@ -318,7 +315,7 @@ I put the following in my main upload view
|
|
318
315
|
The following jQuery code will do an ajax delete for you
|
319
316
|
|
320
317
|
function setup_submit_delete(){
|
321
|
-
jQuery(".submit-delete").click
|
318
|
+
jQuery(".submit-delete").live('click', function() {
|
322
319
|
// if(!confirm("Are you sure?")){
|
323
320
|
// return false;
|
324
321
|
// }
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.1
|
@@ -1,8 +1,8 @@
|
|
1
1
|
class Uploader::UploadsController < ApplicationController
|
2
2
|
unloadable
|
3
3
|
|
4
|
-
before_filter :setup_parent, :only => [:create, :
|
5
|
-
before_filter :filter_permissions, :only => [:create, :
|
4
|
+
before_filter :setup_parent, :only => [:create, :multiupload]
|
5
|
+
before_filter :filter_permissions, :only => [:create, :multiupload]
|
6
6
|
before_filter :set_upload_for_destroy, :only => [:destroy]
|
7
7
|
|
8
8
|
def create
|
@@ -34,19 +34,20 @@ module UploaderHelper
|
|
34
34
|
|
35
35
|
uploadify_options = {
|
36
36
|
:uploader => '/swf/uploadify.swf',
|
37
|
-
:script =>
|
37
|
+
:script => uploads_url,
|
38
38
|
:cancelImg => '/images/uploadify/cancel.png',
|
39
39
|
:fileDesc => "All Files",
|
40
40
|
:fileExt => "*.*",
|
41
41
|
:auto => true,
|
42
42
|
:multi => true,
|
43
43
|
:buttonText => 'Upload',
|
44
|
+
:onComplete => 'oncomplete_replace_',
|
44
45
|
:scriptData => {
|
45
46
|
'_http_accept' => 'application/javascript',
|
46
47
|
'_method' => 'post',
|
47
48
|
"#{session_key}" => 'session_key_replace_',
|
48
49
|
'authenticity_token' => 'authenticity_token_replace_'
|
49
|
-
}
|
50
|
+
}.merge(make_parent_params(parent))
|
50
51
|
}.merge(options)
|
51
52
|
|
52
53
|
uploadify_options_json = uploadify_options.to_json
|
@@ -54,6 +55,7 @@ module UploaderHelper
|
|
54
55
|
# We need it to execute. The double encode is required - u on the server and encodeURIComponent on the client.
|
55
56
|
uploadify_options_json.gsub!('"session_key_replace_"', "encodeURIComponent('#{u(cookies[session_key])}')")
|
56
57
|
uploadify_options_json.gsub!('"authenticity_token_replace_"', "encodeURIComponent('#{u(form_authenticity_token)}')")
|
58
|
+
uploadify_options_json.gsub!('"oncomplete_replace_"', 'function(event, queueID, fileObj, response, data){ upload_completed_callback(response); return true; }')
|
57
59
|
|
58
60
|
render :partial => 'uploads/uploadify', :locals => { :parent => parent,
|
59
61
|
:container_prefix => container_prefix,
|
@@ -7,7 +7,11 @@ module ActiveRecord
|
|
7
7
|
end
|
8
8
|
|
9
9
|
module ClassMethods
|
10
|
-
|
10
|
+
|
11
|
+
# options:
|
12
|
+
# S3_no_wait - Immediately send files to S3 instead of waiting for an aysnc process to send them over.
|
13
|
+
# keep_local_file - If using S3 determines whether or not to keep files local as well as sending to S3.
|
14
|
+
#
|
11
15
|
# acts_as_uploader requires an option for :has_attached_file. These values will be passed to paperclip.
|
12
16
|
# i.e.
|
13
17
|
# acts_as_uploader :has_attached_file => {
|
@@ -19,8 +23,15 @@ module ActiveRecord
|
|
19
23
|
#
|
20
24
|
# disable_halt_nonimage_processing - By default all post processing is turned off for non image files. This is useful if you want to setup styles to generate thumbnails for
|
21
25
|
# images but don't want the default Geometry processor to die on non-image files.
|
22
|
-
def acts_as_uploader(options)
|
26
|
+
def acts_as_uploader(options = {})
|
23
27
|
|
28
|
+
default_options = {
|
29
|
+
:S3_no_wait => false,
|
30
|
+
:keep_local_file => true
|
31
|
+
}
|
32
|
+
|
33
|
+
options = default_options.merge(options)
|
34
|
+
|
24
35
|
#Named scopes
|
25
36
|
named_scope :newest, :order => "created_at DESC"
|
26
37
|
named_scope :by_filename, :order => "local_file_name DESC"
|
@@ -33,6 +44,8 @@ module ActiveRecord
|
|
33
44
|
named_scope :created_by, lambda { |*args| { :conditions => ["creator_id = ?", (args.first) ]} }
|
34
45
|
named_scope :pending_s3_migrations, lambda { { :conditions => ["remote_file_name IS NULL"], :order => 'created_at DESC' } }
|
35
46
|
|
47
|
+
@uploader_s3_no_wait = options.delete(:S3_no_wait)
|
48
|
+
@uploader_keep_file_local = options.delete(:keep_local_file)
|
36
49
|
|
37
50
|
# Paperclip
|
38
51
|
has_attached_file :local, options[:has_attached_file].merge(:storage => :filesystem) # Override any storage settings. This one has to be local.
|
@@ -42,6 +55,8 @@ module ActiveRecord
|
|
42
55
|
|
43
56
|
belongs_to :uploadable, :polymorphic => true
|
44
57
|
belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id'
|
58
|
+
|
59
|
+
before_save :determine_immediate_send_to_remote
|
45
60
|
|
46
61
|
class_eval <<-EOV
|
47
62
|
|
@@ -61,6 +76,14 @@ module ActiveRecord
|
|
61
76
|
# class methods
|
62
77
|
module SingletonMethods
|
63
78
|
|
79
|
+
def s3_no_wait?
|
80
|
+
@uploader_s3_no_wait
|
81
|
+
end
|
82
|
+
|
83
|
+
def keep_local_file?
|
84
|
+
@uploader_keep_file_local
|
85
|
+
end
|
86
|
+
|
64
87
|
end
|
65
88
|
|
66
89
|
# All the methods available to a record that has had <tt>acts_as_uploader</tt> specified.
|
@@ -74,11 +97,17 @@ module ActiveRecord
|
|
74
97
|
remote_file_name || local_file_name
|
75
98
|
end
|
76
99
|
|
100
|
+
def determine_immediate_send_to_remote
|
101
|
+
if self.class.s3_no_wait?
|
102
|
+
self.remote = local.to_file # This will result in the file being sent to S3
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
77
106
|
def send_to_remote
|
78
107
|
if local_file_name
|
79
108
|
self.remote = local.to_file
|
80
109
|
if self.save and remote.original_filename and remote.exists?
|
81
|
-
self.local = nil
|
110
|
+
self.local = nil unless keep_local_file?
|
82
111
|
self.save
|
83
112
|
else
|
84
113
|
false
|
@@ -3,6 +3,16 @@ require File.dirname(__FILE__) + '/../test_helper'
|
|
3
3
|
class UploadTest < ActiveSupport::TestCase
|
4
4
|
|
5
5
|
context "upload" do
|
6
|
+
|
7
|
+
context 'options' do
|
8
|
+
should 'not enable immediate transfers to S3 by default' do
|
9
|
+
assert false == Upload.s3_no_wait?
|
10
|
+
end
|
11
|
+
should 'keep a local copy of each upload by default' do
|
12
|
+
assert true == Upload.keep_local_file?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
6
16
|
context 'upload instance' do
|
7
17
|
|
8
18
|
should belong_to :uploadable
|
data/uploader.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{uploader}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.0.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Justin Ball", "Joel Duffin", "David South"]
|
12
|
-
s.date = %q{2010-08-
|
12
|
+
s.date = %q{2010-08-31}
|
13
13
|
s.description = %q{Uploader gem that makes it simple add multiple file uploads to your Rails project using SWFUpload, Uploadify and Paperclip}
|
14
14
|
s.email = %q{justinball@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uploader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Justin Ball
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-08-
|
20
|
+
date: 2010-08-31 00:00:00 -06:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|