durran-carrierwave 0.3.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Generators +4 -0
- data/History.txt +66 -0
- data/LICENSE +8 -0
- data/Manifest.txt +89 -0
- data/README.rdoc +342 -0
- data/Rakefile +30 -0
- data/carrierwave.gemspec +57 -0
- data/cucumber.yml +2 -0
- data/features/caching.feature +28 -0
- data/features/file_storage.feature +37 -0
- data/features/file_storage_overridden_filename.feature +38 -0
- data/features/file_storage_overridden_store_dir.feature +38 -0
- data/features/file_storage_reversing_processor.feature +43 -0
- data/features/fixtures/bork.txt +1 -0
- data/features/fixtures/monkey.txt +1 -0
- data/features/mount_activerecord.feature +46 -0
- data/features/mount_datamapper.feature +46 -0
- data/features/step_definitions/activerecord_steps.rb +22 -0
- data/features/step_definitions/caching_steps.rb +14 -0
- data/features/step_definitions/datamapper_steps.rb +29 -0
- data/features/step_definitions/file_steps.rb +42 -0
- data/features/step_definitions/general_steps.rb +80 -0
- data/features/step_definitions/mount_steps.rb +19 -0
- data/features/step_definitions/store_steps.rb +18 -0
- data/features/support/activerecord.rb +30 -0
- data/features/support/datamapper.rb +7 -0
- data/features/support/env.rb +35 -0
- data/features/versions_basics.feature +50 -0
- data/features/versions_nested_versions.feature +70 -0
- data/features/versions_overridden_filename.feature +51 -0
- data/features/versions_overriden_store_dir.feature +41 -0
- data/lib/carrierwave.rb +145 -0
- data/lib/carrierwave/compatibility/paperclip.rb +95 -0
- data/lib/carrierwave/core_ext/blank.rb +46 -0
- data/lib/carrierwave/core_ext/inheritable_attributes.rb +104 -0
- data/lib/carrierwave/core_ext/module_setup.rb +51 -0
- data/lib/carrierwave/mount.rb +332 -0
- data/lib/carrierwave/orm/activerecord.rb +73 -0
- data/lib/carrierwave/orm/datamapper.rb +27 -0
- data/lib/carrierwave/orm/mongomapper.rb +27 -0
- data/lib/carrierwave/orm/sequel.rb +57 -0
- data/lib/carrierwave/processing/image_science.rb +72 -0
- data/lib/carrierwave/processing/rmagick.rb +286 -0
- data/lib/carrierwave/sanitized_file.rb +272 -0
- data/lib/carrierwave/storage/abstract.rb +32 -0
- data/lib/carrierwave/storage/file.rb +50 -0
- data/lib/carrierwave/storage/s3.rb +215 -0
- data/lib/carrierwave/test/matchers.rb +114 -0
- data/lib/carrierwave/uploader.rb +43 -0
- data/lib/carrierwave/uploader/cache.rb +116 -0
- data/lib/carrierwave/uploader/callbacks.rb +42 -0
- data/lib/carrierwave/uploader/default_path.rb +23 -0
- data/lib/carrierwave/uploader/extension_whitelist.rb +37 -0
- data/lib/carrierwave/uploader/mountable.rb +39 -0
- data/lib/carrierwave/uploader/paths.rb +27 -0
- data/lib/carrierwave/uploader/processing.rb +81 -0
- data/lib/carrierwave/uploader/proxy.rb +62 -0
- data/lib/carrierwave/uploader/remove.rb +23 -0
- data/lib/carrierwave/uploader/store.rb +156 -0
- data/lib/carrierwave/uploader/url.rb +24 -0
- data/lib/carrierwave/uploader/versions.rb +147 -0
- data/lib/generators/uploader_generator.rb +22 -0
- data/rails_generators/uploader/USAGE +2 -0
- data/rails_generators/uploader/templates/uploader.rb +47 -0
- data/rails_generators/uploader/uploader_generator.rb +21 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/compatibility/paperclip_spec.rb +43 -0
- data/spec/fixtures/bork.txt +1 -0
- data/spec/fixtures/test.jpeg +1 -0
- data/spec/fixtures/test.jpg +1 -0
- data/spec/mount_spec.rb +517 -0
- data/spec/orm/activerecord_spec.rb +271 -0
- data/spec/orm/datamapper_spec.rb +161 -0
- data/spec/orm/mongomapper_spec.rb +184 -0
- data/spec/orm/sequel_spec.rb +192 -0
- data/spec/sanitized_file_spec.rb +612 -0
- data/spec/spec_helper.rb +99 -0
- data/spec/uploader/cache_spec.rb +196 -0
- data/spec/uploader/default_path_spec.rb +68 -0
- data/spec/uploader/extension_whitelist_spec.rb +44 -0
- data/spec/uploader/mountable_spec.rb +33 -0
- data/spec/uploader/paths_spec.rb +22 -0
- data/spec/uploader/processing_spec.rb +62 -0
- data/spec/uploader/proxy_spec.rb +54 -0
- data/spec/uploader/remove_spec.rb +70 -0
- data/spec/uploader/store_spec.rb +274 -0
- data/spec/uploader/url_spec.rb +87 -0
- data/spec/uploader/versions_spec.rb +306 -0
- metadata +228 -0
data/Generators
ADDED
data/History.txt
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
=== Version 0.3.2.3 2009-08-28
|
2
|
+
* Added support for MongoMapper
|
3
|
+
|
4
|
+
=== Version 0.3.2 2009-07-18
|
5
|
+
|
6
|
+
Incremental upgrade
|
7
|
+
|
8
|
+
* [added] Ruby 1.9 compatibility
|
9
|
+
* [changed] Added Object#blank? implementation into CarrierWave, which removes any dpendencies on external libraries (extlib/activesupport)
|
10
|
+
* [fixed] Performance issues with S3 support
|
11
|
+
* [fixed] Sequel support for newer verions of Sequel (thanks Pavel!)
|
12
|
+
|
13
|
+
=== Version 0.3.1 2009-07-01
|
14
|
+
|
15
|
+
A bugfix release. Drop in compatible with 0.3.0.
|
16
|
+
|
17
|
+
* [fixed] Saving a record with a mounted Uploader no longer removes uploaded file
|
18
|
+
* [fixed] The file returned by S3 storage now has the path set to the full store path
|
19
|
+
* [added] File returned by S3 storage now responds to S3 specific methods
|
20
|
+
|
21
|
+
=== 0.3 2009-06-20
|
22
|
+
|
23
|
+
This is a stabilization release. Most features are now working as expected and
|
24
|
+
most bugs should be fixed.
|
25
|
+
|
26
|
+
* [changed] Reworked how storage engines work, some internal API changes
|
27
|
+
* [added] Macro-like methods for RMagick, no need to call #process any more!
|
28
|
+
* [added] Ability to super to any Mount method
|
29
|
+
* [fixed] Sequel support should now work as expected
|
30
|
+
* [fixed] ActiveRecord no longer saves the record twice
|
31
|
+
* [added] Added convenient macro style class methods to rmagick processing
|
32
|
+
|
33
|
+
=== 0.2.4 2009-06-11
|
34
|
+
|
35
|
+
* [added] `resize_to_limit` method for rmagick
|
36
|
+
* [added] Now deletes files from Amazon S3 when record is destroyed
|
37
|
+
|
38
|
+
=== 0.2.3 2009-05-13
|
39
|
+
|
40
|
+
* [changed] Mount now no longer returns nil if there is no stored file, it returns a blank uploader instead
|
41
|
+
* [added] Possibility to specify a default path
|
42
|
+
* [added] Paperclip compatibility module
|
43
|
+
|
44
|
+
=== 0.2.1 2009-05-01
|
45
|
+
|
46
|
+
* [changed] Url method now optionally takes versions as parameters (like Paperclip)
|
47
|
+
* [added] A field which allows files to be removed with a checkbox in mount
|
48
|
+
* [added] Mount_on option for Mount, to be able to override the serialization column
|
49
|
+
* [added] Added demeter friendly column_url method to Mount
|
50
|
+
* [added] Option to not copy files to cache dir, to prevent writes on read only fs systems (this is a workaround and needs a better solution)
|
51
|
+
|
52
|
+
|
53
|
+
=== 0.2 2009-04-15
|
54
|
+
|
55
|
+
* [changed] The version is no longer stored in the store dir. This will break the paths for files uploaded with 0.1
|
56
|
+
* [changed] CarrierWave::Uploader is now a module, not a class, so you need to include it, not inherit from it.
|
57
|
+
* [added] Integiry checking in uploaders via a white list of extensions
|
58
|
+
* [added] Validations for integrity and processing in ActiveRecord, activated by default
|
59
|
+
* [added] Support for nested versions
|
60
|
+
* [added] Permissions option to set the permissions of the uploaded files
|
61
|
+
* [added] Support for Sequel
|
62
|
+
* [added] CarrierWave::Uploader#read to read the contents of the uploaded files
|
63
|
+
|
64
|
+
=== 0.1 2009-03-12
|
65
|
+
|
66
|
+
This is a very experimental release that has not been well tested. All of the major features are in place though. Please note that there currently is a bug with load paths in Merb, which means you need to manually require uploaders.
|
data/LICENSE
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Copyright © 2008 Jonas Nicklas
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
8
|
+
|
data/Manifest.txt
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
Generators
|
2
|
+
History.txt
|
3
|
+
Manifest.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
carrierwave.gemspec
|
7
|
+
cucumber.yml
|
8
|
+
features/caching.feature
|
9
|
+
features/file_storage.feature
|
10
|
+
features/file_storage_overridden_filename.feature
|
11
|
+
features/file_storage_overridden_store_dir.feature
|
12
|
+
features/file_storage_reversing_processor.feature
|
13
|
+
features/fixtures/bork.txt
|
14
|
+
features/fixtures/monkey.txt
|
15
|
+
features/mount_activerecord.feature
|
16
|
+
features/mount_datamapper.feature
|
17
|
+
features/step_definitions/activerecord_steps.rb
|
18
|
+
features/step_definitions/caching_steps.rb
|
19
|
+
features/step_definitions/datamapper_steps.rb
|
20
|
+
features/step_definitions/file_steps.rb
|
21
|
+
features/step_definitions/general_steps.rb
|
22
|
+
features/step_definitions/mount_steps.rb
|
23
|
+
features/step_definitions/store_steps.rb
|
24
|
+
features/support/activerecord.rb
|
25
|
+
features/support/datamapper.rb
|
26
|
+
features/support/env.rb
|
27
|
+
features/versions_basics.feature
|
28
|
+
features/versions_nested_versions.feature
|
29
|
+
features/versions_overridden_filename.feature
|
30
|
+
features/versions_overriden_store_dir.feature
|
31
|
+
lib/carrierwave.rb
|
32
|
+
lib/carrierwave/compatibility/paperclip.rb
|
33
|
+
lib/carrierwave/core_ext/blank.rb
|
34
|
+
lib/carrierwave/core_ext/inheritable_attributes.rb
|
35
|
+
lib/carrierwave/core_ext/module_setup.rb
|
36
|
+
lib/carrierwave/mount.rb
|
37
|
+
lib/carrierwave/orm/activerecord.rb
|
38
|
+
lib/carrierwave/orm/datamapper.rb
|
39
|
+
lib/carrierwave/orm/mongomapper.rb
|
40
|
+
lib/carrierwave/orm/sequel.rb
|
41
|
+
lib/carrierwave/processing/image_science.rb
|
42
|
+
lib/carrierwave/processing/rmagick.rb
|
43
|
+
lib/carrierwave/sanitized_file.rb
|
44
|
+
lib/carrierwave/storage/abstract.rb
|
45
|
+
lib/carrierwave/storage/file.rb
|
46
|
+
lib/carrierwave/storage/s3.rb
|
47
|
+
lib/carrierwave/test/matchers.rb
|
48
|
+
lib/carrierwave/uploader.rb
|
49
|
+
lib/carrierwave/uploader/cache.rb
|
50
|
+
lib/carrierwave/uploader/callbacks.rb
|
51
|
+
lib/carrierwave/uploader/default_path.rb
|
52
|
+
lib/carrierwave/uploader/extension_whitelist.rb
|
53
|
+
lib/carrierwave/uploader/mountable.rb
|
54
|
+
lib/carrierwave/uploader/paths.rb
|
55
|
+
lib/carrierwave/uploader/processing.rb
|
56
|
+
lib/carrierwave/uploader/proxy.rb
|
57
|
+
lib/carrierwave/uploader/remove.rb
|
58
|
+
lib/carrierwave/uploader/store.rb
|
59
|
+
lib/carrierwave/uploader/url.rb
|
60
|
+
lib/carrierwave/uploader/versions.rb
|
61
|
+
lib/generators/uploader_generator.rb
|
62
|
+
rails_generators/uploader/USAGE
|
63
|
+
rails_generators/uploader/templates/uploader.rb
|
64
|
+
rails_generators/uploader/uploader_generator.rb
|
65
|
+
script/console
|
66
|
+
script/destroy
|
67
|
+
script/generate
|
68
|
+
spec/compatibility/paperclip_spec.rb
|
69
|
+
spec/fixtures/bork.txt
|
70
|
+
spec/fixtures/test.jpeg
|
71
|
+
spec/fixtures/test.jpg
|
72
|
+
spec/mount_spec.rb
|
73
|
+
spec/orm/activerecord_spec.rb
|
74
|
+
spec/orm/datamapper_spec.rb
|
75
|
+
spec/orm/mongomapper_spec.rb
|
76
|
+
spec/orm/sequel_spec.rb
|
77
|
+
spec/sanitized_file_spec.rb
|
78
|
+
spec/spec_helper.rb
|
79
|
+
spec/uploader/cache_spec.rb
|
80
|
+
spec/uploader/default_path_spec.rb
|
81
|
+
spec/uploader/extension_whitelist_spec.rb
|
82
|
+
spec/uploader/mountable_spec.rb
|
83
|
+
spec/uploader/paths_spec.rb
|
84
|
+
spec/uploader/processing_spec.rb
|
85
|
+
spec/uploader/proxy_spec.rb
|
86
|
+
spec/uploader/remove_spec.rb
|
87
|
+
spec/uploader/store_spec.rb
|
88
|
+
spec/uploader/url_spec.rb
|
89
|
+
spec/uploader/versions_spec.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,342 @@
|
|
1
|
+
= CarrierWave
|
2
|
+
|
3
|
+
http://carrierwave.rubyforge.org
|
4
|
+
|
5
|
+
== Summary
|
6
|
+
|
7
|
+
This plugin for Merb and Rails provides a simple and extremely flexible way to
|
8
|
+
upload files.
|
9
|
+
|
10
|
+
== Description
|
11
|
+
|
12
|
+
* RDoc Documentation {available at Rubyforge}[http://carrierwave.rubyforge.org/].
|
13
|
+
* Source code {hosted at GitHub}[http://github.com/jnicklas/carrierwave]
|
14
|
+
* Please {report any issues}[http://github.com/jnicklas/carrierwave/issues] on GitHub
|
15
|
+
* Please direct any questions at the {mailing list}[http://groups.google.com/group/carrierwave]
|
16
|
+
|
17
|
+
== Getting Started
|
18
|
+
|
19
|
+
Install the latest stable release:
|
20
|
+
|
21
|
+
[sudo] gem install carrierwave
|
22
|
+
|
23
|
+
Or the cutting edge development version:
|
24
|
+
|
25
|
+
[sudo] gem install jnicklas-carrierwave --source http://gems.github.com
|
26
|
+
|
27
|
+
In Merb, add it as a dependency to your config/dependencies.rb:
|
28
|
+
|
29
|
+
dependency 'carrierwave'
|
30
|
+
|
31
|
+
In Rails, add it to your environment.rb:
|
32
|
+
|
33
|
+
config.gem "carrierwave"
|
34
|
+
|
35
|
+
== Quick Start
|
36
|
+
|
37
|
+
Start off by generating an uploader:
|
38
|
+
|
39
|
+
merb-gen uploader Avatar
|
40
|
+
|
41
|
+
or in Rails:
|
42
|
+
|
43
|
+
script/generate uploader Avatar
|
44
|
+
|
45
|
+
this should give you a file in:
|
46
|
+
|
47
|
+
app/uploaders/avatar_uploader.rb
|
48
|
+
|
49
|
+
Check out this file for some hints on how you can customize your uploader. It
|
50
|
+
should look something like this:
|
51
|
+
|
52
|
+
class AvatarUploader < CarrierWave::Uploader::Base
|
53
|
+
storage :file
|
54
|
+
end
|
55
|
+
|
56
|
+
You can use your uploader class to store and retrieve files like this:
|
57
|
+
|
58
|
+
uploader = AvatarUploader.new
|
59
|
+
|
60
|
+
uploader.store!(my_file)
|
61
|
+
|
62
|
+
uploader.retrieve_from_store!('my_file.png')
|
63
|
+
|
64
|
+
CarrierWave gives you a +store+ for permanent storage, and a +cache+ for
|
65
|
+
temporary storage. You can use different stores, at the moment a filesystem
|
66
|
+
store and an Amazon S3 store are bundled.
|
67
|
+
|
68
|
+
Most of the time you are going to want to use CarrierWave together with an ORM.
|
69
|
+
It is quite simple to mount uploaders on columns in your model, so you can
|
70
|
+
simply assign files and get going:
|
71
|
+
|
72
|
+
=== ActiveRecord, DataMapper, Sequel, MongoMapper
|
73
|
+
|
74
|
+
If you are *not* using Merb or Rails you'll need to require the relevant ORM
|
75
|
+
extension.
|
76
|
+
|
77
|
+
require 'carrierwave/orm/activerecord'
|
78
|
+
require 'carrierwave/orm/datamapper'
|
79
|
+
require 'carrierwave/orm/sequel'
|
80
|
+
require 'carrierwave/orm/mongomapper'
|
81
|
+
|
82
|
+
Open your model file, for ActiveRecord do something like:
|
83
|
+
|
84
|
+
class User < ActiveRecord::Base
|
85
|
+
mount_uploader :avatar, AvatarUploader
|
86
|
+
end
|
87
|
+
|
88
|
+
Or for DataMapper:
|
89
|
+
|
90
|
+
class User
|
91
|
+
include DataMapper::Resource
|
92
|
+
|
93
|
+
mount_uploader :avatar, AvatarUploader
|
94
|
+
end
|
95
|
+
|
96
|
+
Or for Sequel
|
97
|
+
|
98
|
+
class User < Sequel::Model
|
99
|
+
mount_uploader :avatar, AvatarUploader
|
100
|
+
end
|
101
|
+
|
102
|
+
Now you can cache files by assigning them to the attribute, they will
|
103
|
+
automatically be stored when the record is saved.
|
104
|
+
|
105
|
+
u = User.new
|
106
|
+
u.avatar = params[:file]
|
107
|
+
u.avatar = File.open('somewhere')
|
108
|
+
u.save!
|
109
|
+
u.avatar.url # => '/url/to/file.png'
|
110
|
+
u.avatar.current_path # => 'path/to/file.png'
|
111
|
+
|
112
|
+
== Changing the storage directory
|
113
|
+
|
114
|
+
In order to change where uploaded files are put, just override the +store_dir+
|
115
|
+
method:
|
116
|
+
|
117
|
+
class MyUploader < CarrierWave::Uploader::Base
|
118
|
+
def store_dir
|
119
|
+
'public/my/upload/directory'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
This works for the file storage as well as Amazon S3.
|
124
|
+
|
125
|
+
== Adding versions
|
126
|
+
|
127
|
+
Often you'll want to add different versions of the same file. The classic
|
128
|
+
example is image thumbnails. There is built in support for this:
|
129
|
+
|
130
|
+
class MyUploader < CarrierWave::Uploader::Base
|
131
|
+
include CarrierWave::RMagick
|
132
|
+
|
133
|
+
process :resize => [800, 800]
|
134
|
+
|
135
|
+
version :thumb do
|
136
|
+
process :crop_resized => [200,200]
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
When this uploader is used, an uploaded image would be scaled to be no larger
|
142
|
+
than 800 by 800 pixels. A version called thumb is then created, which is scaled
|
143
|
+
and cropped to exactly 200 by 200 pixels. The uploader could be used like this:
|
144
|
+
|
145
|
+
uploader = AvatarUploader.new
|
146
|
+
uploader.store!(my_file) # size: 1024x768
|
147
|
+
|
148
|
+
uploader.url # => '/url/to/my_file.png' # size: 800x600
|
149
|
+
uploader.thumb.url # => '/url/to/thumb_my_file.png' # size: 200x200
|
150
|
+
|
151
|
+
One important thing to remember is that process is called *before* versions are
|
152
|
+
created. This can cut down on processing cost.
|
153
|
+
|
154
|
+
It is possible to nest versions within versions:
|
155
|
+
|
156
|
+
class MyUploader < CarrierWave::Uploader::Base
|
157
|
+
|
158
|
+
version :animal do
|
159
|
+
version :human
|
160
|
+
version :monkey
|
161
|
+
version :llama
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
== Making uploads work across form redisplays
|
166
|
+
|
167
|
+
Often you'll notice that uploaded files disappear when a validation fails.
|
168
|
+
CarrierWave has a feature that makes it easy to remember the uploaded file even
|
169
|
+
in that case. Suppose your +user+ model has an uploader mounted on +avatar+
|
170
|
+
file, just add a hidden field called +avatar_cache+. In Rails, this would look
|
171
|
+
like this:
|
172
|
+
|
173
|
+
<% form_for @user do |f| %>
|
174
|
+
<p>
|
175
|
+
<label>My Avatar</label>
|
176
|
+
<%= f.file_field :avatar %>
|
177
|
+
<%= f.hidden_field :avatar_cache %>
|
178
|
+
</p>
|
179
|
+
<% end %>
|
180
|
+
|
181
|
+
It might be a good idea to show th user that a file has been uploaded, in the
|
182
|
+
case of images, a small thumbnail would be a good indicator:
|
183
|
+
|
184
|
+
<% form_for @user do |f| %>
|
185
|
+
<p>
|
186
|
+
<label>My Avatar</label>
|
187
|
+
<%= image_tag(@user.avatar.url) if @user.avatar %>
|
188
|
+
<%= f.file_field :avatar %>
|
189
|
+
<%= f.hidden_field :avatar_cache %>
|
190
|
+
</p>
|
191
|
+
<% end %>
|
192
|
+
|
193
|
+
NOTE: this feature currently requires write access to your filesystem. If write
|
194
|
+
access is unavailable you will not be able to upload files. You can prevent
|
195
|
+
CarrierWave from writing to the file system by setting
|
196
|
+
`CarrierWave.config[:cache_to_cache_dir] = false`. This will however break
|
197
|
+
redisplays of forms.
|
198
|
+
|
199
|
+
== Providing a default path
|
200
|
+
|
201
|
+
In many cases, especially when working with images, it might be a good idea to
|
202
|
+
provide a default path, a fallback in case no file has been uploaded. You can do
|
203
|
+
this easily by overriding the +default_path+ method in your uploader:
|
204
|
+
|
205
|
+
class MyUploader < CarrierWave::Uploader::Base
|
206
|
+
def default_path
|
207
|
+
"images/fallback/" + [version_name, "default.png"].compact.join('_')
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
== Using Amazon S3
|
212
|
+
|
213
|
+
You'll need to configure a bucket, access id and secret key like this:
|
214
|
+
|
215
|
+
CarrierWave.config[:s3][:access_key_id] = 'xxxxxx'
|
216
|
+
CarrierWave.config[:s3][:secret_access_key] = 'xxxxxx'
|
217
|
+
CarrierWave.config[:s3][:bucket] = 'name_of_bucket'
|
218
|
+
|
219
|
+
Do this in an initializer in Rails, and in a +before_app_loads+ block in Merb.
|
220
|
+
|
221
|
+
And then in your uploader, set the storage to :s3
|
222
|
+
|
223
|
+
class AvatarUploader <
|
224
|
+
storage :s3
|
225
|
+
end
|
226
|
+
|
227
|
+
That's it! You can still use the +CarrierWave::Uploader#url+ method to return
|
228
|
+
the url to the file on Amazon S3
|
229
|
+
|
230
|
+
== Using RMagick
|
231
|
+
|
232
|
+
If you're uploading images, you'll probably want to manipulate them in some way,
|
233
|
+
you might want to create thumbnail images for example. CarrierWave comes with a
|
234
|
+
small library to make manipulating images with RMagick easier, you'll need to
|
235
|
+
include it in your Uploader:
|
236
|
+
|
237
|
+
class AvatarUploader < CarrierWave::Uploader::Base
|
238
|
+
include CarrierWave::RMagick
|
239
|
+
end
|
240
|
+
|
241
|
+
The RMagick module gives you a few methods, like
|
242
|
+
+CarrierWave::RMagick#crop_resized+ which manipulate the image file in some way.
|
243
|
+
You can set a +process+ callback, which will call that method any time a file is
|
244
|
+
uploaded.
|
245
|
+
|
246
|
+
class AvatarUploader < CarrierWave::Uploader::Base
|
247
|
+
include CarrierWave::RMagick
|
248
|
+
|
249
|
+
process :crop_resized => [200, 200]
|
250
|
+
process :convert => 'png'
|
251
|
+
|
252
|
+
def filename
|
253
|
+
super + '.png'
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
Check out the manipulate! method, which makes it easy for you to write your own
|
258
|
+
manipulation methods.
|
259
|
+
|
260
|
+
== Using ImageScience
|
261
|
+
|
262
|
+
ImageScience works the same way as RMagick.
|
263
|
+
|
264
|
+
class AvatarUploader < CarrierWave::Uploader::Base
|
265
|
+
include CarrierWave::ImageScience
|
266
|
+
|
267
|
+
process :crop_resized => [200, 200]
|
268
|
+
end
|
269
|
+
|
270
|
+
== Migrating
|
271
|
+
|
272
|
+
If you are using Paperclip, you can use the provided compatibility module:
|
273
|
+
|
274
|
+
class AvatarUploader < CarrierWave::Uploader::Base
|
275
|
+
include CarrierWave::Compatibility::Paperclip
|
276
|
+
end
|
277
|
+
|
278
|
+
See the documentation for +Paperclip::Compatibility::Paperclip+ for more
|
279
|
+
detaills.
|
280
|
+
|
281
|
+
Be sure to use mount_on to specify the correct column:
|
282
|
+
|
283
|
+
mount_uploader :avatar, AvatarUploader, :mount_on => :avatar_file_name
|
284
|
+
|
285
|
+
Unfortunately AttachmentFoo differs too much in philosophy for there to be a
|
286
|
+
sensible compatibility mode. Patches for migrating from other solutions will be
|
287
|
+
happily accepted.
|
288
|
+
|
289
|
+
== i18n
|
290
|
+
|
291
|
+
The activerecord validations use the Rails i18n framework. Add these keys to
|
292
|
+
your translations file:
|
293
|
+
|
294
|
+
carrierwave:
|
295
|
+
errors:
|
296
|
+
integrity: 'Not an image.'
|
297
|
+
processing: 'Cannot resize image.'
|
298
|
+
|
299
|
+
== Contributors
|
300
|
+
|
301
|
+
These people have contributed their time and effort to CarrierWave:
|
302
|
+
|
303
|
+
* Jonas Nicklas
|
304
|
+
* Pavel Kunc
|
305
|
+
* Andrew Timberlake
|
306
|
+
|
307
|
+
== License
|
308
|
+
|
309
|
+
Copyright (c) 2008 Jonas Nicklas
|
310
|
+
|
311
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
312
|
+
a copy of this software and associated documentation files (the
|
313
|
+
"Software"), to deal in the Software without restriction, including
|
314
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
315
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
316
|
+
permit persons to whom the Software is furnished to do so, subject to
|
317
|
+
the following conditions:
|
318
|
+
|
319
|
+
The above copyright notice and this permission notice shall be
|
320
|
+
included in all copies or substantial portions of the Software.
|
321
|
+
|
322
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
323
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
324
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
325
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
326
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
327
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
328
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
329
|
+
|
330
|
+
== Development
|
331
|
+
|
332
|
+
If you want to run the tests (and you should) it might be convenient to install
|
333
|
+
the development dependencies, you can do that with:
|
334
|
+
|
335
|
+
sudo gem install carrierwave --development
|
336
|
+
|
337
|
+
CarrierWave is still young, but most of it is pretty well documented. It is also
|
338
|
+
extensively specced, and there are cucumber features for some common use cases.
|
339
|
+
Just dig in and look at the source for more in-depth explanation of what things
|
340
|
+
are doing.
|
341
|
+
|
342
|
+
Issues are reported on GitHub, pull requests are very welcome!
|