locomotive_carrierwave 0.5.0.1 → 0.5.4.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/README.md +714 -0
  2. data/lib/carrierwave.rb +9 -3
  3. data/lib/carrierwave/compatibility/paperclip.rb +18 -18
  4. data/lib/carrierwave/mount.rb +30 -25
  5. data/lib/carrierwave/orm/activerecord.rb +14 -4
  6. data/lib/carrierwave/orm/mongoid.rb +29 -8
  7. data/lib/carrierwave/processing/image_science.rb +25 -2
  8. data/lib/carrierwave/processing/mini_magick.rb +4 -3
  9. data/lib/carrierwave/processing/rmagick.rb +3 -2
  10. data/lib/carrierwave/sanitized_file.rb +23 -38
  11. data/lib/carrierwave/storage/abstract.rb +0 -3
  12. data/lib/carrierwave/storage/cloud_files.rb +30 -10
  13. data/lib/carrierwave/storage/file.rb +1 -8
  14. data/lib/carrierwave/storage/fog.rb +332 -0
  15. data/lib/carrierwave/storage/grid_fs.rb +6 -6
  16. data/lib/carrierwave/storage/s3.rb +31 -34
  17. data/lib/carrierwave/test/matchers.rb +1 -1
  18. data/lib/carrierwave/uploader.rb +0 -1
  19. data/lib/carrierwave/uploader/cache.rb +28 -7
  20. data/lib/carrierwave/uploader/callbacks.rb +11 -17
  21. data/lib/carrierwave/uploader/configuration.rb +62 -34
  22. data/lib/carrierwave/uploader/download.rb +16 -5
  23. data/lib/carrierwave/uploader/extension_whitelist.rb +14 -3
  24. data/lib/carrierwave/uploader/mountable.rb +1 -1
  25. data/lib/carrierwave/uploader/processing.rb +20 -15
  26. data/lib/carrierwave/uploader/proxy.rb +16 -1
  27. data/lib/carrierwave/uploader/store.rb +3 -9
  28. data/lib/carrierwave/uploader/url.rb +3 -2
  29. data/lib/carrierwave/uploader/versions.rb +78 -25
  30. data/lib/carrierwave/version.rb +1 -1
  31. data/lib/generators/templates/uploader.rb +2 -1
  32. metadata +64 -102
  33. data/README.rdoc +0 -532
  34. data/lib/carrierwave/orm/datamapper.rb +0 -37
  35. data/lib/carrierwave/orm/sequel.rb +0 -45
  36. data/lib/carrierwave/uploader/rename.rb +0 -62
data/README.md ADDED
@@ -0,0 +1,714 @@
1
+ # CarrierWave
2
+
3
+ This gem provides a simple and extremely flexible way to upload files from Ruby applications.
4
+ It works well with Rack based web applications, such as Ruby on Rails.
5
+
6
+ ## Information
7
+
8
+ * RDoc documentation [available on RubyDoc.info](http://rubydoc.info/gems/carrierwave/frames)
9
+ * Source code [available on GitHub](http://github.com/jnicklas/carrierwave)
10
+ * More information, known limitations, and how-tos [available on the wiki](https://github.com/jnicklas/carrierwave/wiki)
11
+
12
+ ## Getting Help
13
+
14
+ * Please ask the [Google Group](http://groups.google.com/group/carrierwave) for help if you have any questions.
15
+ * Please report bugs on the [issue tracker](http://github.com/jnicklas/carrierwave/issues) but read the "getting help" section in the wiki first.
16
+
17
+ ## Installation
18
+
19
+ Install the latest stable release:
20
+
21
+ [sudo] gem install carrierwave
22
+
23
+ In Rails, add it to your Gemfile:
24
+
25
+ ``` ruby
26
+ gem 'carrierwave'
27
+ ```
28
+
29
+ Note that CarrierWave is not compatible with Rails 2 as of version 0.5. If you want to use
30
+ Rails 2, please use the 0.4-stable branch on GitHub.
31
+
32
+ ## Getting Started
33
+
34
+ Start off by generating an uploader:
35
+
36
+ rails generate uploader Avatar
37
+
38
+ this should give you a file in:
39
+
40
+ app/uploaders/avatar_uploader.rb
41
+
42
+ Check out this file for some hints on how you can customize your uploader. It
43
+ should look something like this:
44
+
45
+ ``` ruby
46
+ class AvatarUploader < CarrierWave::Uploader::Base
47
+ storage :file
48
+ end
49
+ ```
50
+
51
+ You can use your uploader class to store and retrieve files like this:
52
+
53
+ ``` ruby
54
+ uploader = AvatarUploader.new
55
+
56
+ uploader.store!(my_file)
57
+
58
+ uploader.retrieve_from_store!('my_file.png')
59
+ ```
60
+
61
+ CarrierWave gives you a `store` for permanent storage, and a `cache` for
62
+ temporary storage. You can use different stores, at the moment a filesystem
63
+ store, an Amazon S3 store, a Rackspace Cloud Files store, and a store for
64
+ MongoDB's GridFS are bundled.
65
+
66
+ Most of the time you are going to want to use CarrierWave together with an ORM.
67
+ It is quite simple to mount uploaders on columns in your model, so you can
68
+ simply assign files and get going:
69
+
70
+ ### ActiveRecord, Mongoid
71
+
72
+ Make sure you are loading CarrierWave after loading your ORM, otherwise you'll
73
+ need to require the relevant extension manually, e.g.:
74
+
75
+ ``` ruby
76
+ require 'carrierwave/orm/activerecord'
77
+ ```
78
+
79
+ Add a string column to the model you want to mount the uploader on:
80
+
81
+ ``` ruby
82
+ add_column :users, :avatar, :string
83
+ ```
84
+
85
+ Open your model file and mount the uploader:
86
+
87
+ ``` ruby
88
+ class User
89
+ mount_uploader :avatar, AvatarUploader
90
+ end
91
+ ```
92
+
93
+ This works the same with all supported ORMs.
94
+
95
+ Now you can cache files by assigning them to the attribute, they will
96
+ automatically be stored when the record is saved.
97
+
98
+ ``` ruby
99
+ u = User.new
100
+ u.avatar = params[:file]
101
+ u.avatar = File.open('somewhere')
102
+ u.save!
103
+ u.avatar.url # => '/url/to/file.png'
104
+ u.avatar.current_path # => 'path/to/file.png'
105
+ ```
106
+
107
+ If using Mongoid, note that embedded documents files aren't saved when parent documents are saved.
108
+ You must explicitly call save on embedded documents in order to save their attached files.
109
+ You can read more about this [here](https://github.com/jnicklas/carrierwave/issues#issue/81)
110
+
111
+ ### DataMapper, Sequel
112
+
113
+ Other ORM support has been extracted into separate gems. Learn more:
114
+
115
+ * [carrierwave-datamapper](https://github.com/jnicklas/carrierwave-datamapper)
116
+ * [carrierwave-sequel](https://github.com/jnicklas/carrierwave-sequel)
117
+
118
+ There are more extensions listed in [the wiki](https://github.com/jnicklas/carrierwave/wiki)
119
+
120
+ ## Changing the storage directory
121
+
122
+ In order to change where uploaded files are put, just override the `store_dir`
123
+ method:
124
+
125
+ ``` ruby
126
+ class MyUploader < CarrierWave::Uploader::Base
127
+ def store_dir
128
+ 'public/my/upload/directory'
129
+ end
130
+ end
131
+ ```
132
+
133
+ This works for the file storage as well as Amazon S3 and Rackspace Cloud Files.
134
+ Define `store_dir` as `nil` if you'd like to store files at the root level.
135
+
136
+ ## Securing uploads
137
+
138
+ Certain file might be dangerous if uploaded to the wrong location, such as php
139
+ files or other script files. CarrierWave allows you to specify a white-list of
140
+ allowed extensions.
141
+
142
+ If you're mounting the uploader, uploading a file with the wrong extension will
143
+ make the record invalid instead. Otherwise, an error is raised.
144
+
145
+ ``` ruby
146
+ class MyUploader < CarrierWave::Uploader::Base
147
+ def extension_white_list
148
+ %w(jpg jpeg gif png)
149
+ end
150
+ end
151
+ ```
152
+
153
+ ### Filenames and unicode chars
154
+
155
+ Another security issue you should care for is the file names (see
156
+ [Ruby On Rails Security Guide](http://guides.rubyonrails.org/security.html#file-uploads)).
157
+ By default, CarrierWave provides only English letters, arabic numerals and '-+_.' symbols as
158
+ white-listed characters in the file name. If you want to support local scripts (Cyrillic letters, letters with diacritics and so on), you
159
+ have to override `sanitize_regexp` method. It should return regular expression which would match
160
+ all *non*-allowed symbols.
161
+
162
+ With Ruby 1.9 and higher you can simply write (as it has [Oniguruma](http://oniguruma.rubyforge.org/oniguruma/)
163
+ built-in):
164
+
165
+ ``` ruby
166
+ CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/
167
+ ```
168
+
169
+ With Ruby 1.8 you have to manually specify all character ranges. For example, for files which may
170
+ contain Russian letters:
171
+
172
+ ``` ruby
173
+ CarrierWave::SanitizedFile.sanitize_regexp = /[^a-zA-Zа-яА-ЯёЁ0-9\.\-\+_]/u
174
+ ```
175
+
176
+ Also make sure that allowing non-latin characters won't cause a compatibility issue with a third-party
177
+ plugins or client-side software.
178
+
179
+ ## Adding versions
180
+
181
+ Often you'll want to add different versions of the same file. The classic
182
+ example is image thumbnails. There is built in support for this:
183
+
184
+ ``` ruby
185
+ class MyUploader < CarrierWave::Uploader::Base
186
+ include CarrierWave::RMagick
187
+
188
+ process :resize_to_fit => [800, 800]
189
+
190
+ version :thumb do
191
+ process :resize_to_fill => [200,200]
192
+ end
193
+
194
+ end
195
+ ```
196
+
197
+ When this uploader is used, an uploaded image would be scaled to be no larger
198
+ than 800 by 800 pixels. A version called thumb is then created, which is scaled
199
+ and cropped to exactly 200 by 200 pixels. The uploader could be used like this:
200
+
201
+ ``` ruby
202
+ uploader = AvatarUploader.new
203
+ uploader.store!(my_file) # size: 1024x768
204
+
205
+ uploader.url # => '/url/to/my_file.png' # size: 800x600
206
+ uploader.thumb.url # => '/url/to/thumb_my_file.png' # size: 200x200
207
+ ```
208
+
209
+ One important thing to remember is that process is called *before* versions are
210
+ created. This can cut down on processing cost.
211
+
212
+ It is possible to nest versions within versions:
213
+
214
+ ``` ruby
215
+ class MyUploader < CarrierWave::Uploader::Base
216
+
217
+ version :animal do
218
+ version :human
219
+ version :monkey
220
+ version :llama
221
+ end
222
+ end
223
+ ```
224
+
225
+ ## Making uploads work across form redisplays
226
+
227
+ Often you'll notice that uploaded files disappear when a validation fails.
228
+ CarrierWave has a feature that makes it easy to remember the uploaded file even
229
+ in that case. Suppose your `user` model has an uploader mounted on `avatar`
230
+ file, just add a hidden field called `avatar_cache`. In Rails, this would look
231
+ like this:
232
+
233
+ ``` erb
234
+ <%= form_for @user, :html => {:multipart => true} do |f| %>
235
+ <p>
236
+ <label>My Avatar</label>
237
+ <%= f.file_field :avatar %>
238
+ <%= f.hidden_field :avatar_cache %>
239
+ </p>
240
+ <% end %>
241
+ ````
242
+
243
+ It might be a good idea to show the user that a file has been uploaded, in the
244
+ case of images, a small thumbnail would be a good indicator:
245
+
246
+ ``` erb
247
+ <%= form_for @user, :html => {:multipart => true} do |f| %>
248
+ <p>
249
+ <label>My Avatar</label>
250
+ <%= image_tag(@user.avatar_url) if @user.avatar? %>
251
+ <%= f.file_field :avatar %>
252
+ <%= f.hidden_field :avatar_cache %>
253
+ </p>
254
+ <% end %>
255
+ ```
256
+
257
+ ## Removing uploaded files
258
+
259
+ If you want to remove a previously uploaded file on a mounted uploader, you can
260
+ easily add a checkbox to the form which will remove the file when checked.
261
+
262
+ ``` erb
263
+ <%= form_for @user, :html => {:multipart => true} do |f| %>
264
+ <p>
265
+ <label>My Avatar</label>
266
+ <%= image_tag(@user.avatar_url) if @user.avatar? %>
267
+ <%= f.file_field :avatar %>
268
+ </p>
269
+
270
+ <p>
271
+ <label>
272
+ <%= f.check_box :remove_avatar %>
273
+ Remove avatar
274
+ </label>
275
+ </p>
276
+ <% end %>
277
+ ```
278
+
279
+ If you want to remove the file manually, you can call <code>remove_avatar!</code>.
280
+
281
+ ## Uploading files from a remote location
282
+
283
+ Your users may find it convenient to upload a file from a location on the Internet
284
+ via a URL. CarrierWave makes this simple, just add the appropriate attribute to your
285
+ form and you're good to go:
286
+
287
+ ``` erb
288
+ <%= form_for @user, :html => {:multipart => true} do |f| %>
289
+ <p>
290
+ <label>My Avatar URL:</label>
291
+ <%= image_tag(@user.avatar_url) if @user.avatar? %>
292
+ <%= f.text_field :remote_avatar_url %>
293
+ </p>
294
+ <% end %>
295
+ ```
296
+
297
+ ## Providing a default URL
298
+
299
+ In many cases, especially when working with images, it might be a good idea to
300
+ provide a default url, a fallback in case no file has been uploaded. You can do
301
+ this easily by overriding the `default_url` method in your uploader:
302
+
303
+ ``` ruby
304
+ class MyUploader < CarrierWave::Uploader::Base
305
+ def default_url
306
+ "/images/fallback/" + [version_name, "default.png"].compact.join('_')
307
+ end
308
+ end
309
+ ```
310
+
311
+ ## Recreating versions
312
+
313
+ You might come to a situation where you want to retroactively change a version
314
+ or add a new one. You can use the recreate_versions! method to recreate the
315
+ versions from the base file. This uses a naive approach which will re-upload and
316
+ process all versions.
317
+
318
+ ``` ruby
319
+ instance = MyUploader.new
320
+ instance.recreate_versions!
321
+ ```
322
+
323
+ Or on a mounted uploader:
324
+
325
+ ``` ruby
326
+ User.all.each do |user|
327
+ user.avatar.recreate_versions!
328
+ end
329
+ ```
330
+
331
+ ## Configuring CarrierWave
332
+
333
+ CarrierWave has a broad range of configuration options, which you can configure,
334
+ both globally and on a per-uploader basis:
335
+
336
+ ``` ruby
337
+ CarrierWave.configure do |config|
338
+ config.permissions = 0666
339
+ config.storage = :s3
340
+ end
341
+ ```
342
+
343
+ Or alternatively:
344
+
345
+ ``` ruby
346
+ class AvatarUploader < CarrierWave::Uploader::Base
347
+ permissions 0777
348
+ end
349
+ ```
350
+
351
+ If you're using Rails, create an initializer for this:
352
+
353
+ ``` ruby
354
+ config/initializers/carrierwave.rb
355
+ ```
356
+
357
+ ## Testing with CarrierWave
358
+
359
+ It's a good idea to test you uploaders in isolation. In order to speed up your
360
+ tests, it's recommended to switch off processing in your tests, and to use the
361
+ file storage. In Rails you could do that by adding an initializer with:
362
+
363
+ ``` ruby
364
+ if Rails.env.test? or Rails.env.cucumber?
365
+ CarrierWave.configure do |config|
366
+ config.storage = :file
367
+ config.enable_processing = false
368
+ end
369
+ end
370
+ ```
371
+
372
+ If you need to test your processing, you should test it in isolation, and enable
373
+ processing only for those tests that need it.
374
+
375
+ CarrierWave comes with some RSpec matchers which you may find useful:
376
+
377
+ ``` ruby
378
+ require 'carrierwave/test/matchers'
379
+
380
+ describe MyUploader do
381
+ include CarrierWave::Test::Matchers
382
+
383
+ before do
384
+ MyUploader.enable_processing = true
385
+ @uploader = MyUploader.new(@user, :avatar)
386
+ @uploader.store!(File.open(path_to_file))
387
+ end
388
+
389
+ after do
390
+ MyUploader.enable_processing = false
391
+ end
392
+
393
+ context 'the thumb version' do
394
+ it "should scale down a landscape image to be exactly 64 by 64 pixels" do
395
+ @uploader.thumb.should have_dimensions(64, 64)
396
+ end
397
+ end
398
+
399
+ context 'the small version' do
400
+ it "should scale down a landscape image to fit within 200 by 200 pixels" do
401
+ @uploader.small.should be_no_larger_than(200, 200)
402
+ end
403
+ end
404
+
405
+ it "should make the image readable only to the owner and not executable" do
406
+ @uploader.should have_permissions(0600)
407
+ end
408
+ end
409
+ ```
410
+
411
+ Setting the enable_processing flag on an uploader will prevent any of the versions from processing as well.
412
+ Processing can be enabled for a single version by setting the processing flag on the version like so:
413
+
414
+ ``` ruby
415
+ @uploader.thumb.enable_processing = true
416
+ ```
417
+
418
+ ## Using Amazon S3
419
+
420
+ [Fog](http://github.com/geemus/fog) is used to support Amazon S3. Ensure you have it installed:
421
+
422
+ gem install fog
423
+
424
+ You'll need to provide your fog_credentials and a fog_directory (also known as a bucket) in an initializer.
425
+ For the sake of performance it is assumed that the directory already exists, so please create it if need be.
426
+ You can also pass in additional options, as documented fully in lib/carrierwave/storage/fog.rb. Here's a full example:
427
+
428
+ ``` ruby
429
+ CarrierWave.configure do |config|
430
+ config.fog_credentials = {
431
+ :provider => 'AWS', # required
432
+ :aws_access_key_id => 'xxx', # required
433
+ :aws_secret_access_key => 'yyy', # required
434
+ :region => 'eu-west-1' # optional, defaults to 'us-east-1'
435
+ }
436
+ config.fog_directory = 'name_of_directory' # required
437
+ config.fog_host = 'https://assets.example.com' # optional, defaults to nil
438
+ config.fog_public = false # optional, defaults to true
439
+ config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
440
+ end
441
+ ```
442
+
443
+ In your uploader, set the storage to :fog
444
+
445
+ ``` ruby
446
+ class AvatarUploader < CarrierWave::Uploader::Base
447
+ storage :fog
448
+ end
449
+ ```
450
+
451
+ That's it! You can still use the `CarrierWave::Uploader#url` method to return the url to the file on Amazon S3.
452
+
453
+ ## Using Rackspace Cloud Files
454
+
455
+ [Fog](http://github.com/geemus/fog) is used to support Rackspace Cloud Files. Ensure you have it installed:
456
+
457
+ gem install fog
458
+
459
+ You'll need to configure a directory (also known as a container), username and API key in the initializer.
460
+ For the sake of performance it is assumed that the directory already exists, so please create it if need be.
461
+
462
+ ``` ruby
463
+ CarrierWave.configure do |config|
464
+ config.fog_credentials = {
465
+ :provider => 'Rackspace',
466
+ :rackspace_username => 'xxxxxx',
467
+ :rackspace_api_key => 'yyyyyy'
468
+ }
469
+ config.fog_directory = 'name_of_directory'
470
+ end
471
+ ```
472
+
473
+ You can optionally include your CDN host name in the configuration.
474
+ This is *highly* recommended, as without it every request requires a lookup
475
+ of this information.
476
+
477
+ ``` ruby
478
+ config.fog_host = "c000000.cdn.rackspacecloud.com"
479
+ ```
480
+
481
+ In your uploader, set the storage to :fog
482
+
483
+ ``` ruby
484
+ class AvatarUploader < CarrierWave::Uploader::Base
485
+ storage :fog
486
+ end
487
+ ```
488
+
489
+ That's it! You can still use the `CarrierWave::Uploader#url` method to return
490
+ the url to the file on Rackspace Cloud Files.
491
+
492
+ ## Using Google Storage for Developers
493
+
494
+ [Fog](http://github.com/geemus/fog) is used to support Google Storage for Developers. Ensure you have it installed:
495
+
496
+ gem install fog
497
+
498
+ You'll need to configure a directory (also known as a bucket), access key id and secret access key in the initializer.
499
+ For the sake of performance it is assumed that the directory already exists, so please create it if need be.
500
+
501
+ ``` ruby
502
+ CarrierWave.configure do |config|
503
+ config.fog_credentials = {
504
+ :provider => 'Google',
505
+ :google_storage_access_key_id => 'xxxxxx',
506
+ :google_storage_secret_access_key => 'yyyyyy'
507
+ }
508
+ config.fog_directory = 'name_of_directory'
509
+ end
510
+ ```
511
+
512
+ In your uploader, set the storage to :fog
513
+
514
+ ``` ruby
515
+ class AvatarUploader < CarrierWave::Uploader::Base
516
+ storage :fog
517
+ end
518
+ ```
519
+
520
+ That's it! You can still use the `CarrierWave::Uploader#url` method to return
521
+ the url to the file on Google.
522
+
523
+ ## Using MongoDB's GridFS store
524
+
525
+ You'll need to configure the database and host to use:
526
+
527
+ ``` ruby
528
+ CarrierWave.configure do |config|
529
+ config.grid_fs_database = 'my_mongo_database'
530
+ config.grid_fs_host = 'mongo.example.com'
531
+ end
532
+ ```
533
+
534
+ The defaults are 'carrierwave' and 'localhost'.
535
+
536
+ And then in your uploader, set the storage to `:grid_fs`:
537
+
538
+ ``` ruby
539
+ class AvatarUploader < CarrierWave::Uploader::Base
540
+ storage :grid_fs
541
+ end
542
+ ```
543
+
544
+ Since GridFS doesn't make the files available via HTTP, you'll need to stream
545
+ them yourself. In Rails for example, you could use the `send_data` method. You
546
+ can tell CarrierWave the URL you will serve your images from, allowing it to
547
+ generate the correct URL, by setting eg:
548
+
549
+ ``` ruby
550
+ CarrierWave.configure do |config|
551
+ config.grid_fs_access_url = "/image/show"
552
+ end
553
+ ```
554
+
555
+ ## Using RMagick
556
+
557
+ If you're uploading images, you'll probably want to manipulate them in some way,
558
+ you might want to create thumbnail images for example. CarrierWave comes with a
559
+ small library to make manipulating images with RMagick easier, you'll need to
560
+ include it in your Uploader:
561
+
562
+ ``` ruby
563
+ class AvatarUploader < CarrierWave::Uploader::Base
564
+ include CarrierWave::RMagick
565
+ end
566
+ ```
567
+
568
+ The RMagick module gives you a few methods, like
569
+ `CarrierWave::RMagick#resize_to_fill` which manipulate the image file in some
570
+ way. You can set a `process` callback, which will call that method any time a
571
+ file is uploaded.
572
+
573
+ ``` ruby
574
+ class AvatarUploader < CarrierWave::Uploader::Base
575
+ include CarrierWave::RMagick
576
+
577
+ process :resize_to_fill => [200, 200]
578
+ process :convert => 'png'
579
+
580
+ def filename
581
+ super + '.png'
582
+ end
583
+ end
584
+ ```
585
+
586
+ Check out the manipulate! method, which makes it easy for you to write your own
587
+ manipulation methods.
588
+
589
+ ## Using ImageScience
590
+
591
+ ImageScience works the same way as RMagick.
592
+
593
+ ``` ruby
594
+ class AvatarUploader < CarrierWave::Uploader::Base
595
+ include CarrierWave::ImageScience
596
+
597
+ process :resize_to_fill => [200, 200]
598
+ end
599
+ ```
600
+
601
+ ## Using MiniMagick
602
+
603
+ MiniMagick is similar to RMagick but performs all the operations using the 'mogrify'
604
+ command which is part of the standard ImageMagick kit. This allows you to have the power
605
+ of ImageMagick without having to worry about installing all the RMagick libraries.
606
+
607
+ See the MiniMagick site for more details:
608
+
609
+ http://github.com/probablycorey/mini_magick
610
+
611
+ And the ImageMagick command line options for more for whats on offer:
612
+
613
+ http://www.imagemagick.org/script/command-line-options.php
614
+
615
+ Currently, the MiniMagick carrierwave processor provides exactly the same methods as
616
+ for the RMagick processor.
617
+
618
+ ``` ruby
619
+ class AvatarUploader < CarrierWave::Uploader::Base
620
+ include CarrierWave::MiniMagick
621
+
622
+ process :resize_to_fill => [200, 200]
623
+ end
624
+ ```
625
+
626
+ ## Migrating from Paperclip
627
+
628
+ If you are using Paperclip, you can use the provided compatibility module:
629
+
630
+ ``` ruby
631
+ class AvatarUploader < CarrierWave::Uploader::Base
632
+ include CarrierWave::Compatibility::Paperclip
633
+ end
634
+ ```
635
+
636
+ See the documentation for `CarrierWave::Compatibility::Paperclip` for more
637
+ details.
638
+
639
+ Be sure to use mount_on to specify the correct column:
640
+
641
+ ``` ruby
642
+ mount_uploader :avatar, AvatarUploader, :mount_on => :avatar_file_name
643
+ ```
644
+
645
+ Unfortunately attachment_fu differs too much in philosophy for there to be a
646
+ sensible compatibility mode. Patches for migrating from other solutions will be
647
+ happily accepted.
648
+
649
+ ## i18n
650
+
651
+ The Active Record validations use the Rails i18n framework. Add these keys to
652
+ your translations file:
653
+
654
+ ``` yaml
655
+ errors:
656
+ messages:
657
+ carrierwave_processing_error: 'Cannot resize image.'
658
+ carrierwave_integrity_error: 'Not an image.'
659
+ ```
660
+
661
+ ## Contributing to CarrierWave
662
+
663
+ CarrierWave thrives on a large number of [contributors](https://github.com/jnicklas/carrierwave/contributors),
664
+ and pull requests are very welcome. Before submitting a pull request, please make sure that your changes are well tested.
665
+
666
+ You'll need to install bundler and the gem dependencies:
667
+
668
+ gem install bundler
669
+ bundle install
670
+
671
+ You should now be able to run the local tests:
672
+
673
+ bundle exec rake
674
+
675
+ You can also run the remote specs by creating a ~/.fog file:
676
+
677
+ ``` yaml
678
+ :carrierwave:
679
+ :aws_access_key_id: xxx
680
+ :aws_secret_access_key: yyy
681
+ :rackspace_username: xxx
682
+ :rackspace_api_key: yyy
683
+ :google_storage_access_key_id: xxx
684
+ :google_storage_secret_access_key: yyy
685
+ ```
686
+
687
+ You should now be able to run the remote tests:
688
+
689
+ REMOTE=true bundle exec rake
690
+
691
+ Please test with the latest Ruby 1.8.x and 1.9.x versions using RVM if possible.
692
+
693
+ ## License
694
+
695
+ Copyright (c) 2008 Jonas Nicklas
696
+
697
+ Permission is hereby granted, free of charge, to any person obtaining
698
+ a copy of this software and associated documentation files (the
699
+ "Software"), to deal in the Software without restriction, including
700
+ without limitation the rights to use, copy, modify, merge, publish,
701
+ distribute, sublicense, and/or sell copies of the Software, and to
702
+ permit persons to whom the Software is furnished to do so, subject to
703
+ the following conditions:
704
+
705
+ The above copyright notice and this permission notice shall be
706
+ included in all copies or substantial portions of the Software.
707
+
708
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
709
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
710
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
711
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
712
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
713
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
714
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.