uploader 0.1.3 → 0.1.7
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 +81 -33
- data/Rakefile +2 -2
- data/TODO +2 -1
- data/VERSION +1 -1
- data/app/controllers/uploader/uploads_controller.rb +13 -9
- data/app/views/uploads/_swf_upload.html.erb +1 -1
- data/lib/active_record/acts/uploader_upload.rb +12 -13
- data/lib/daemons/amazonaws.rb +36 -0
- data/lib/uploader/tasks.rb +9 -3
- data/public/images/file_icons/excel.gif +0 -0
- data/public/images/file_icons/file.gif +0 -0
- data/public/images/file_icons/file.png +0 -0
- data/public/images/file_icons/file_aac.gif +0 -0
- data/public/images/file_icons/file_ai.gif +0 -0
- data/public/images/file_icons/file_avi.gif +0 -0
- data/public/images/file_icons/file_bin.gif +0 -0
- data/public/images/file_icons/file_bmp.gif +0 -0
- data/public/images/file_icons/file_cue.gif +0 -0
- data/public/images/file_icons/file_divx.gif +0 -0
- data/public/images/file_icons/file_doc.gif +0 -0
- data/public/images/file_icons/file_eps.gif +0 -0
- data/public/images/file_icons/file_flac.gif +0 -0
- data/public/images/file_icons/file_flv.gif +0 -0
- data/public/images/file_icons/file_gif.gif +0 -0
- data/public/images/file_icons/file_html.gif +0 -0
- data/public/images/file_icons/file_ical.gif +0 -0
- data/public/images/file_icons/file_indd.gif +0 -0
- data/public/images/file_icons/file_inx.gif +0 -0
- data/public/images/file_icons/file_iso.gif +0 -0
- data/public/images/file_icons/file_jpg.gif +0 -0
- data/public/images/file_icons/file_mov.gif +0 -0
- data/public/images/file_icons/file_mp3.gif +0 -0
- data/public/images/file_icons/file_mpg.gif +0 -0
- data/public/images/file_icons/file_pdf.gif +0 -0
- data/public/images/file_icons/file_php.gif +0 -0
- data/public/images/file_icons/file_png.gif +0 -0
- data/public/images/file_icons/file_pps.gif +0 -0
- data/public/images/file_icons/file_ppt.gif +0 -0
- data/public/images/file_icons/file_psd.gif +0 -0
- data/public/images/file_icons/file_qxd.gif +0 -0
- data/public/images/file_icons/file_qxp.gif +0 -0
- data/public/images/file_icons/file_raw.gif +0 -0
- data/public/images/file_icons/file_rtf.gif +0 -0
- data/public/images/file_icons/file_svg.gif +0 -0
- data/public/images/file_icons/file_tif.gif +0 -0
- data/public/images/file_icons/file_txt.gif +0 -0
- data/public/images/file_icons/file_vcf.gif +0 -0
- data/public/images/file_icons/file_wav.gif +0 -0
- data/public/images/file_icons/file_wma.gif +0 -0
- data/public/images/file_icons/file_xls.gif +0 -0
- data/public/images/file_icons/file_xml.gif +0 -0
- data/public/images/file_icons/pdf.gif +0 -0
- data/public/images/file_icons/pdf.png +0 -0
- data/public/images/file_icons/text.gif +0 -0
- data/public/images/file_icons/text.png +0 -0
- data/rdoc/classes/ActionController/Routing/RouteSet.html +148 -0
- data/rdoc/classes/ActionController/Routing.html +107 -0
- data/rdoc/classes/ActionController.html +107 -0
- data/rdoc/classes/ActiveRecord/Acts/UploaderUpload/ClassMethods.html +188 -0
- data/rdoc/classes/ActiveRecord/Acts/UploaderUpload/InstanceMethods.html +750 -0
- data/rdoc/classes/ActiveRecord/Acts/UploaderUpload/SingletonMethods.html +111 -0
- data/rdoc/classes/ActiveRecord.html +105 -0
- data/rdoc/classes/Uploader/Exceptions/MissingTemplateError.html +111 -0
- data/rdoc/classes/Uploader/Exceptions.html +111 -0
- data/rdoc/classes/Uploader/FlashSessionCookieMiddleware.html +177 -0
- data/rdoc/classes/Uploader/MimeTypeGroups.html +143 -0
- data/rdoc/classes/Uploader/Tasks.html +146 -0
- data/rdoc/classes/Uploader.html +126 -0
- data/rdoc/created.rid +1 -0
- data/rdoc/files/README_rdoc.html +427 -0
- data/rdoc/files/lib/active_record/acts/uploader_upload_rb.html +101 -0
- data/rdoc/files/lib/uploader/exceptions_rb.html +101 -0
- data/rdoc/files/lib/uploader/initialize_routes_rb.html +101 -0
- data/rdoc/files/lib/uploader/middleware/flash_session_cookie_middleware_rb.html +108 -0
- data/rdoc/files/lib/uploader/mime_type_groups_rb.html +101 -0
- data/rdoc/files/lib/uploader/tasks_rb.html +110 -0
- data/rdoc/files/lib/uploader_rb.html +112 -0
- data/rdoc/fr_class_index.html +39 -0
- data/rdoc/fr_file_index.html +34 -0
- data/rdoc/fr_method_index.html +54 -0
- data/rdoc/index.html +24 -0
- data/rdoc/rdoc-style.css +208 -0
- data/uploader.gemspec +72 -20
- metadata +72 -5
- data/pkg/uploader-0.1.0.gem +0 -0
- data/pkg/uploader-0.1.1.gem +0 -0
- data/pkg/uploader-0.1.2.gem +0 -0
data/README.rdoc
CHANGED
|
@@ -17,28 +17,41 @@ sudo gem install uploader
|
|
|
17
17
|
config.gem 'uploader'
|
|
18
18
|
|
|
19
19
|
|
|
20
|
+
=== Install jQuery
|
|
21
|
+
uploader uses jQuery. You'll need to include it in your application. Download it here:
|
|
22
|
+
http://jquery.com/
|
|
23
|
+
|
|
24
|
+
Then include it in your layout:
|
|
25
|
+
<%= javascript_include_tag 'jquery/jquery.js' %>
|
|
26
|
+
|
|
27
|
+
Another option is to use jRails
|
|
28
|
+
http://ennerchi.com/projects/jrails
|
|
29
|
+
|
|
20
30
|
=== Create a model for uploads.
|
|
21
31
|
We recommend creating a model called upload.rb. acts_as_uploader accepts all valid options for paperclip via :has_attached_file => {}
|
|
22
32
|
|
|
23
33
|
class Upload < ActiveRecord::Base
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
|
|
35
|
+
acts_as_uploader :enable_s3 => false,
|
|
36
|
+
:has_attached_file => {
|
|
37
|
+
:url => "/system/:attachment/:id_partition/:style/:basename.:extension",
|
|
38
|
+
:path => ":rails_root/public/system/:attachment/:id_partition/:style/:basename.:extension",
|
|
39
|
+
:styles => { :icon => "30x30!",
|
|
40
|
+
:thumb => "100>",
|
|
41
|
+
:small => "150>",
|
|
42
|
+
:medium => "300>",
|
|
43
|
+
:large => "660>" },
|
|
44
|
+
:default_url => "/images/profile_default.jpg",
|
|
45
|
+
:storage => :s3,
|
|
46
|
+
:s3_credentials => AMAZON_S3_CREDENTIALS,
|
|
47
|
+
:bucket => "assets.example.com",
|
|
48
|
+
:s3_host_alias => "assets.example.com",
|
|
49
|
+
:convert_options => {
|
|
50
|
+
:all => '-quality 80'
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
:s3_path => ':id_partition/:style/:basename.:extension'
|
|
54
|
+
|
|
42
55
|
# only allow images:
|
|
43
56
|
# validates_attachment_content_type :file, :content_type => ['image/jpeg', 'image/pjpeg', 'image/jpg']
|
|
44
57
|
|
|
@@ -97,7 +110,7 @@ controller instead of directly using the one inside the gem:
|
|
|
97
110
|
|
|
98
111
|
class UploadsController < Uploader::UploadsController
|
|
99
112
|
|
|
100
|
-
|
|
113
|
+
prepend_before_filter :login_required
|
|
101
114
|
|
|
102
115
|
protected
|
|
103
116
|
|
|
@@ -123,6 +136,7 @@ controller instead of directly using the one inside the gem:
|
|
|
123
136
|
|
|
124
137
|
# Simply attempts to redirect to the parent object. You might want to build something more sophisticated that
|
|
125
138
|
# redirect to different areas of you site depending on the type of object that was uploaded or on based on the parent.
|
|
139
|
+
# source can be :destroy_success, :create_success, :create_failure, :permission_denied
|
|
126
140
|
def get_redirect
|
|
127
141
|
@parent
|
|
128
142
|
end
|
|
@@ -143,19 +157,6 @@ controller instead of directly using the one inside the gem:
|
|
|
143
157
|
|
|
144
158
|
end
|
|
145
159
|
|
|
146
|
-
|
|
147
|
-
=== Other Methods
|
|
148
|
-
|
|
149
|
-
uploader assumes that you have a method called 'redirect_back_or_default' which is common in many Rails projects. This method
|
|
150
|
-
is called upon completion of destroy or created when the requested format is 'html'. A simple implementation of this method is listed
|
|
151
|
-
below:
|
|
152
|
-
|
|
153
|
-
def redirect_back_or_default(default)
|
|
154
|
-
redirect_to(session[:return_to] || default)
|
|
155
|
-
session[:return_to] = nil
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
|
|
159
160
|
=== Configure your views.
|
|
160
161
|
You'll need something like this in your layout so that uploader can add in the required css and javascript files.
|
|
161
162
|
|
|
@@ -209,7 +210,54 @@ Create a file named s3.yml in your configuration directory and add the following
|
|
|
209
210
|
There are a number of timing issues that you will run into if you attempt to upload files directly to s3. To overcome that
|
|
210
211
|
problem uploader includes a daemon process which will send the files to Amazon asynchronously. Note that the uploader
|
|
211
212
|
will leave your local copy in place.
|
|
212
|
-
|
|
213
|
+
|
|
214
|
+
Add the daemons gem and plugin:
|
|
215
|
+
sudo gem install daemons
|
|
216
|
+
|
|
217
|
+
Then inside your Rails project:
|
|
218
|
+
script/plugin install git://github.com/dougal/daemon_generator.git
|
|
219
|
+
script/generate daemon amazonaws
|
|
220
|
+
|
|
221
|
+
RAILS_ENV=development lib/daemons/mailer_ctl start
|
|
222
|
+
|
|
223
|
+
Learn more about the custom daemon gem with Ryan Bates screencast:
|
|
224
|
+
http://railscasts.com/episodes/129-custom-daemon
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
== Use Rake to send files to s3
|
|
228
|
+
uploader includes a task capable of sending files to s3 but it makes an assumption that the model you are interacting with
|
|
229
|
+
is named 'Upload'.
|
|
230
|
+
|
|
231
|
+
rake uploader:upload_to_s3
|
|
232
|
+
|
|
233
|
+
If you want to use a different model or several models just add a rake task to your project:
|
|
234
|
+
|
|
235
|
+
desc 'Send all uploads to S3. (Will only send uploads from a model named Upload)'
|
|
236
|
+
task :upload_to_s3 do
|
|
237
|
+
|
|
238
|
+
uploads = Upload.pending_s3_migration
|
|
239
|
+
uploads.each do |upload|
|
|
240
|
+
upload.remote = upload.local
|
|
241
|
+
upload.save!
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
photos = Photo.pending_s3_migration
|
|
245
|
+
photos.each do |photo|
|
|
246
|
+
photo.remote = photo.local
|
|
247
|
+
photo.save!
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
== Setup Domains
|
|
253
|
+
If you use Amazon's S3 service you can setup a cname to clean up your urls. Configure your s3 bucket as above:
|
|
254
|
+
|
|
255
|
+
:bucket => "assets.example.com"
|
|
256
|
+
:s3_host_alias => "assets.example.com"
|
|
257
|
+
|
|
258
|
+
Your assets will be available at assets.example.com.s3.amazon.com. You can then create a CNAME in your DNS entries
|
|
259
|
+
to point "assets.example.com" to "assets.example.com.s3.amazon.com". Your assets will then appear to be
|
|
260
|
+
be served from assets.example.com even though they are loaded from Amazon.
|
|
213
261
|
|
|
214
262
|
|
|
215
263
|
== Other Stuff
|
data/Rakefile
CHANGED
|
@@ -18,7 +18,7 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
|
18
18
|
rdoc.rdoc_dir = 'rdoc'
|
|
19
19
|
rdoc.title = 'Uploader'
|
|
20
20
|
rdoc.options << '--line-numbers' << '--inline-source'
|
|
21
|
-
rdoc.rdoc_files.include('README')
|
|
21
|
+
rdoc.rdoc_files.include('README.rdoc')
|
|
22
22
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
23
23
|
end
|
|
24
24
|
|
|
@@ -31,7 +31,7 @@ begin
|
|
|
31
31
|
gemspec.homepage = "http://github.com/jbasdf/uploader"
|
|
32
32
|
gemspec.description = "Uploader gem that makes it simple add multiple file uploads to your Rails project using SWFUpload and Paperclip"
|
|
33
33
|
gemspec.authors = ["Justin Ball", "David South"]
|
|
34
|
-
gemspec.files.include %w( tasks/rails.rake lib/uploader/*.rb lib/uploader/middleware/*.rb db/migrate/*.rb public/images/file_icons/* app/views/uploads/* )
|
|
34
|
+
#gemspec.files.include %w( tasks/rails.rake lib/uploader/*.rb lib/uploader/middleware/*.rb db/migrate/*.rb public/images/file_icons/* app/views/uploads/* )
|
|
35
35
|
gemspec.rubyforge_project = 'uploader'
|
|
36
36
|
end
|
|
37
37
|
rescue LoadError
|
data/TODO
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.7
|
|
@@ -7,7 +7,7 @@ class Uploader::UploadsController < ApplicationController
|
|
|
7
7
|
def create
|
|
8
8
|
# Standard, one-at-a-time, upload action
|
|
9
9
|
@upload = @parent.uploads.build(params[:upload])
|
|
10
|
-
@upload.creator =
|
|
10
|
+
@upload.creator = get_creator
|
|
11
11
|
@upload.save!
|
|
12
12
|
message = t('uploader.successful_upload')
|
|
13
13
|
upload_json = basic_uploads_json(@upload)
|
|
@@ -15,7 +15,7 @@ class Uploader::UploadsController < ApplicationController
|
|
|
15
15
|
respond_to do |format|
|
|
16
16
|
format.html do
|
|
17
17
|
flash[:notice] = message
|
|
18
|
-
redirect_to
|
|
18
|
+
redirect_to get_redirect(:create_success)
|
|
19
19
|
end
|
|
20
20
|
format.js { render :text => get_upload_text(@upload) }
|
|
21
21
|
format.json { render :json => upload_json }
|
|
@@ -25,7 +25,7 @@ class Uploader::UploadsController < ApplicationController
|
|
|
25
25
|
respond_to do |format|
|
|
26
26
|
format.html do
|
|
27
27
|
flash[:notice] = message
|
|
28
|
-
|
|
28
|
+
redirect_to get_redirect(:create_failure)
|
|
29
29
|
end
|
|
30
30
|
format.js { render :text => message }
|
|
31
31
|
format.json { render :json => { :success => false, :message => message } }
|
|
@@ -35,8 +35,8 @@ class Uploader::UploadsController < ApplicationController
|
|
|
35
35
|
def swfupload
|
|
36
36
|
@upload = @parent.uploads.build
|
|
37
37
|
@upload.is_public = true if params[:is_public] == true
|
|
38
|
-
@upload.creator =
|
|
39
|
-
@upload.swfupload_local = params[:
|
|
38
|
+
@upload.creator = get_creator
|
|
39
|
+
@upload.swfupload_local = params[:filedata]
|
|
40
40
|
@upload.save!
|
|
41
41
|
@parent.uploads << @upload
|
|
42
42
|
respond_to do |format|
|
|
@@ -64,7 +64,7 @@ class Uploader::UploadsController < ApplicationController
|
|
|
64
64
|
respond_to do |format|
|
|
65
65
|
format.html do
|
|
66
66
|
flash[:notice] = message
|
|
67
|
-
|
|
67
|
+
redirect_to get_redirect(:destroy_success)
|
|
68
68
|
end
|
|
69
69
|
format.js { render :text => message }
|
|
70
70
|
format.json { render :json => { :success => success, :message => message } }
|
|
@@ -86,7 +86,7 @@ class Uploader::UploadsController < ApplicationController
|
|
|
86
86
|
respond_to do |format|
|
|
87
87
|
format.html do
|
|
88
88
|
flash[:notice] = message
|
|
89
|
-
redirect_to get_redirect
|
|
89
|
+
redirect_to get_redirect(:permission_denied)
|
|
90
90
|
end
|
|
91
91
|
format.js { render :text => message }
|
|
92
92
|
format.json { render :json => { :success => false, :message => message } }
|
|
@@ -94,8 +94,8 @@ class Uploader::UploadsController < ApplicationController
|
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
# override this method in your controller to set the redirect file upload completion
|
|
97
|
-
#
|
|
98
|
-
def get_redirect
|
|
97
|
+
# source can be :destroy_success, :create_success, :create_failure, :permission_denied
|
|
98
|
+
def get_redirect(source)
|
|
99
99
|
@parent
|
|
100
100
|
end
|
|
101
101
|
|
|
@@ -111,6 +111,10 @@ class Uploader::UploadsController < ApplicationController
|
|
|
111
111
|
end
|
|
112
112
|
end
|
|
113
113
|
|
|
114
|
+
def get_creator
|
|
115
|
+
current_user
|
|
116
|
+
end
|
|
117
|
+
|
|
114
118
|
def has_permission_to_upload(user, upload_parent)
|
|
115
119
|
upload_parent.can_upload?(user)
|
|
116
120
|
end
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
<span class="legend"></span>
|
|
13
13
|
<input id="swf_cancel_button" type="button" value="<%=t('uploader.cancel_all')%>" style="display:none;" />
|
|
14
14
|
<p id="divStatus"></p>
|
|
15
|
-
</div>
|
|
15
|
+
</div>
|
|
16
16
|
</div>
|
|
17
17
|
<noscript class="swf-error-msg">
|
|
18
18
|
<%= t('uploader.javascript_not_enabled') %>
|
|
@@ -26,16 +26,14 @@ module ActiveRecord
|
|
|
26
26
|
named_scope :documents, :conditions => "local_content_type IN (#{(Uploader::MimeTypeGroups::WORD_TYPES + Uploader::MimeTypeGroups::EXCEL_TYPES + Uploader::MimeTypeGroups::PDF_TYPES).collect{|type| "'#{type}'"}.join(',')})"
|
|
27
27
|
named_scope :files, :conditions => "local_content_type NOT IN (#{Uploader::MimeTypeGroups::IMAGE_TYPES.collect{|type| "'#{type}'"}.join(',')})"
|
|
28
28
|
named_scope :since, lambda { |*args| { :conditions => ["created_at > ?", (args.first || 7.days.ago.to_s(:db)) ]} }
|
|
29
|
-
named_scope :pending_s3_migration, lambda {
|
|
30
|
-
|
|
31
|
-
:order => 'created_at DESC',
|
|
32
|
-
:limit => 1 }
|
|
33
|
-
}
|
|
34
|
-
|
|
29
|
+
named_scope :pending_s3_migration, lambda { { :conditions => ["remote_file_name IS NULL AND created_at <= ?", 20.minutes.ago.to_s(:db)], :order => 'created_at DESC' } }
|
|
30
|
+
|
|
35
31
|
# Paperclip
|
|
36
32
|
has_attached_file :local, options[:has_attached_file].merge(:storage => :filesystem) # Override any storage settings. This one has to be local.
|
|
37
33
|
if options[:enable_s3] == true
|
|
38
|
-
has_attached_file :remote, options[:has_attached_file]
|
|
34
|
+
has_attached_file :remote, options[:has_attached_file].merge(:url => ':s3_alias_url',
|
|
35
|
+
:path => options[:s3_path],
|
|
36
|
+
:storage => :s3)
|
|
39
37
|
end
|
|
40
38
|
|
|
41
39
|
|
|
@@ -44,6 +42,7 @@ module ActiveRecord
|
|
|
44
42
|
|
|
45
43
|
class_eval <<-EOV
|
|
46
44
|
validates_attachment_size :local, :less_than => 10.megabytes
|
|
45
|
+
|
|
47
46
|
before_post_process :transliterate_file_name
|
|
48
47
|
before_create :add_width_and_height
|
|
49
48
|
|
|
@@ -133,19 +132,19 @@ module ActiveRecord
|
|
|
133
132
|
|
|
134
133
|
def icon
|
|
135
134
|
if self.is_pdf?
|
|
136
|
-
'/images/file_icons/
|
|
135
|
+
'/images/file_icons/file_pdf.gif'
|
|
137
136
|
elsif self.is_word?
|
|
138
|
-
'/images/file_icons/
|
|
137
|
+
'/images/file_icons/file_doc.gif'
|
|
139
138
|
elsif self.is_image?
|
|
140
139
|
self.file.url(:icon)
|
|
141
140
|
elsif self.is_mp3?
|
|
142
|
-
'/images/file_icons/
|
|
141
|
+
'/images/file_icons/file_mp3.gif'
|
|
143
142
|
elsif self.is_excel?
|
|
144
|
-
'/images/file_icons/
|
|
143
|
+
'/images/file_icons/file_xls.gif'
|
|
145
144
|
elsif self.is_text?
|
|
146
|
-
'/images/file_icons/
|
|
145
|
+
'/images/file_icons/file_txt.gif'
|
|
147
146
|
else
|
|
148
|
-
'/images/file_icons/
|
|
147
|
+
'/images/file_icons/file_raw.gif'
|
|
149
148
|
end
|
|
150
149
|
end
|
|
151
150
|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# You might want to change this
|
|
4
|
+
ENV["RAILS_ENV"] ||= "production"
|
|
5
|
+
|
|
6
|
+
require File.dirname(__FILE__) + "/../../config/environment"
|
|
7
|
+
|
|
8
|
+
$running = true
|
|
9
|
+
Signal.trap("TERM") do
|
|
10
|
+
$running = false
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Waiting is a timer variable to allow the daemon to restart
|
|
14
|
+
# within two seconds of the Signal rather than using a long
|
|
15
|
+
# sleep command and forcing the daemon to wait.
|
|
16
|
+
$waiting = 0
|
|
17
|
+
|
|
18
|
+
ActiveRecord::Base.logger.info "[AmazonS3] Migration daemon started at #{Time.now}.\n"
|
|
19
|
+
|
|
20
|
+
while($running) do
|
|
21
|
+
|
|
22
|
+
if $waiting < 120
|
|
23
|
+
$waiting += 2
|
|
24
|
+
sleep 2
|
|
25
|
+
else
|
|
26
|
+
$waiting = 0
|
|
27
|
+
upload = Upload.pending_s3_migration.first
|
|
28
|
+
|
|
29
|
+
if upload
|
|
30
|
+
$waiting = 120 - 2
|
|
31
|
+
ActiveRecord::Base.logger.info "[AmazonS3] Migrating upload ##{upload.id}\n"
|
|
32
|
+
upload.remote = upload.local
|
|
33
|
+
upload.save!
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
data/lib/uploader/tasks.rb
CHANGED
|
@@ -16,17 +16,23 @@ module Uploader
|
|
|
16
16
|
Rake::Task[:environment].invoke if defined?(RAILS_ROOT)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
desc 'Send all uploads to S3'
|
|
19
|
+
desc 'Send all uploads to S3. (Will only send uploads from a model named Upload)'
|
|
20
20
|
task :upload_to_s3 do
|
|
21
|
-
|
|
21
|
+
uploads = Upload.pending_s3_migration
|
|
22
|
+
uploads.each do |upload|
|
|
23
|
+
upload.remote = upload.local
|
|
24
|
+
upload.save!
|
|
25
|
+
end
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
desc "Sync required files from uploader."
|
|
25
29
|
task :sync do
|
|
26
30
|
path = File.join(File.dirname(__FILE__), *%w[.. ..])
|
|
27
|
-
|
|
31
|
+
daemons_path = "#{RAILS_ROOT}/lib/daemons"
|
|
28
32
|
system "rsync -ruv #{path}/public ."
|
|
29
33
|
system "rsync -ruv #{path}/db ."
|
|
34
|
+
FileUtils.mkdir_p(daemons_path) unless File.directory?(daemons_path)
|
|
35
|
+
FileUtils.cp_r("#{path}/lib/daemons/amazonaws.rb", "#{RAILS_ROOT}/lib/daemons/amazonaws.rb")
|
|
30
36
|
end
|
|
31
37
|
|
|
32
38
|
end
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|