carrierwave 0.11.2 → 1.1.0

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.

Potentially problematic release.


This version of carrierwave might be problematic. Click here for more details.

Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +223 -116
  3. data/lib/carrierwave/compatibility/paperclip.rb +0 -2
  4. data/lib/carrierwave/error.rb +1 -0
  5. data/lib/carrierwave/locale/en.yml +7 -4
  6. data/lib/carrierwave/mount.rb +219 -176
  7. data/lib/carrierwave/mounter.rb +165 -0
  8. data/lib/carrierwave/orm/activerecord.rb +49 -20
  9. data/lib/carrierwave/processing/mini_magick.rb +69 -15
  10. data/lib/carrierwave/processing/rmagick.rb +32 -4
  11. data/lib/carrierwave/processing.rb +0 -1
  12. data/lib/carrierwave/sanitized_file.rb +43 -38
  13. data/lib/carrierwave/storage/abstract.rb +15 -2
  14. data/lib/carrierwave/storage/file.rb +65 -2
  15. data/lib/carrierwave/storage/fog.rb +105 -28
  16. data/lib/carrierwave/storage.rb +0 -9
  17. data/lib/carrierwave/test/matchers.rb +77 -12
  18. data/lib/carrierwave/uploader/cache.rb +41 -27
  19. data/lib/carrierwave/uploader/callbacks.rb +0 -2
  20. data/lib/carrierwave/uploader/configuration.rb +50 -7
  21. data/lib/carrierwave/uploader/default_url.rb +3 -5
  22. data/lib/carrierwave/uploader/download.rb +10 -7
  23. data/lib/carrierwave/uploader/extension_blacklist.rb +14 -10
  24. data/lib/carrierwave/uploader/extension_whitelist.rb +12 -10
  25. data/lib/carrierwave/uploader/file_size.rb +41 -0
  26. data/lib/carrierwave/uploader/magic_mime_blacklist.rb +94 -0
  27. data/lib/carrierwave/uploader/magic_mime_whitelist.rb +94 -0
  28. data/lib/carrierwave/uploader/mountable.rb +7 -8
  29. data/lib/carrierwave/uploader/processing.rb +10 -10
  30. data/lib/carrierwave/uploader/proxy.rb +5 -7
  31. data/lib/carrierwave/uploader/remove.rb +0 -2
  32. data/lib/carrierwave/uploader/serialization.rb +1 -3
  33. data/lib/carrierwave/uploader/store.rb +5 -23
  34. data/lib/carrierwave/uploader/url.rb +3 -5
  35. data/lib/carrierwave/uploader/versions.rb +75 -82
  36. data/lib/carrierwave/uploader.rb +2 -2
  37. data/lib/carrierwave/utilities/uri.rb +4 -7
  38. data/lib/carrierwave/utilities.rb +0 -3
  39. data/lib/carrierwave/validations/active_model.rb +0 -2
  40. data/lib/carrierwave/version.rb +1 -1
  41. data/lib/carrierwave.rb +8 -10
  42. data/lib/generators/templates/uploader.rb +4 -6
  43. metadata +41 -95
  44. data/lib/carrierwave/locale/cs.yml +0 -11
  45. data/lib/carrierwave/locale/de.yml +0 -11
  46. data/lib/carrierwave/locale/el.yml +0 -11
  47. data/lib/carrierwave/locale/es.yml +0 -11
  48. data/lib/carrierwave/locale/fr.yml +0 -11
  49. data/lib/carrierwave/locale/ja.yml +0 -11
  50. data/lib/carrierwave/locale/nb.yml +0 -11
  51. data/lib/carrierwave/locale/nl.yml +0 -11
  52. data/lib/carrierwave/locale/pl.yml +0 -11
  53. data/lib/carrierwave/locale/pt-BR.yml +0 -11
  54. data/lib/carrierwave/locale/pt-PT.yml +0 -11
  55. data/lib/carrierwave/locale/ru.yml +0 -11
  56. data/lib/carrierwave/locale/sk.yml +0 -11
  57. data/lib/carrierwave/locale/tr.yml +0 -11
  58. data/lib/carrierwave/processing/mime_types.rb +0 -74
  59. data/lib/carrierwave/utilities/deprecation.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c1689fd908e56b671c45e5cb1eebe3ec938a4df
4
- data.tar.gz: 89668d77484c786139f513dc1b82c82879da4e11
3
+ metadata.gz: 637cc1f96fe4f41cc4468837e5f3ea358e80ed6e
4
+ data.tar.gz: 7e160616b11d78c39bee758a90412dbadb588c04
5
5
  SHA512:
6
- metadata.gz: a03780cb6e64ad439c1f12378be2f4392617dbbe9f83329eccc6bc05064385e0e95a4b4609e32d922a0ce6d5543bbc795eb4abb8e429d5e366040fdfa3c82bfd
7
- data.tar.gz: ee26ab882ed995b677c38e6064843101633a07166cf2dda0e522bf1b13eb7a30a373312d67b786bc86365fd3ef4cb974f8f57a564dafbf9eafaf1c60b7e3e3e8
6
+ metadata.gz: 9757ab08f11fee70c9337f706dce60d20f12200890ed1816f6eedc0fb2939e282c9290d724ccaa592f3c78bf91f5f643b3af0bd27240bd7ced5132068af1e45e
7
+ data.tar.gz: 768e9c140fba9bd1f3dd299cdf83b94cc4348a1888801793a638d6a20220c2eff152916a6066bcb0b586f96080039e7594c13c89b352d4711699502110772293
data/README.md CHANGED
@@ -3,8 +3,10 @@
3
3
  This gem provides a simple and extremely flexible way to upload files from Ruby applications.
4
4
  It works well with Rack based web applications, such as Ruby on Rails.
5
5
 
6
- [![Build Status](https://travis-ci.org/carrierwaveuploader/carrierwave.png?branch=master)](http://travis-ci.org/carrierwaveuploader/carrierwave)
7
- [![Code Climate](https://codeclimate.com/github/carrierwaveuploader/carrierwave.png)](https://codeclimate.com/github/carrierwaveuploader/carrierwave)
6
+ [![Build Status](https://travis-ci.org/carrierwaveuploader/carrierwave.svg?branch=master)](http://travis-ci.org/carrierwaveuploader/carrierwave)
7
+ [![Code Climate](http://img.shields.io/codeclimate/github/carrierwaveuploader/carrierwave.svg)](https://codeclimate.com/github/carrierwaveuploader/carrierwave)
8
+ [![git.legal](https://git.legal/projects/1363/badge.svg "Number of libraries approved")](https://git.legal/projects/1363)
9
+
8
10
 
9
11
  ## Information
10
12
 
@@ -14,25 +16,27 @@ It works well with Rack based web applications, such as Ruby on Rails.
14
16
 
15
17
  ## Getting Help
16
18
 
17
- * Please ask the [Google Group](http://groups.google.com/group/carrierwave) for help if you have any questions.
19
+ * Please ask the community on [Stack Overflow](https://stackoverflow.com/questions/tagged/carrierwave) for help if you have any questions. Please do not post usage questions on the issue tracker.
18
20
  * Please report bugs on the [issue tracker](http://github.com/carrierwaveuploader/carrierwave/issues) but read the "getting help" section in the wiki first.
19
21
 
20
22
  ## Installation
21
23
 
22
- Install the latest stable release:
24
+ Install the latest release:
23
25
 
24
- [sudo] gem install carrierwave
26
+ ```
27
+ $ gem install carrierwave -v "1.0.0"
28
+ ```
25
29
 
26
30
  In Rails, add it to your Gemfile:
27
31
 
28
32
  ```ruby
29
- gem 'carrierwave'
33
+ gem 'carrierwave', '~> 1.0'
30
34
  ```
31
35
 
32
36
  Finally, restart the server to apply the changes.
33
37
 
34
- Note that CarrierWave is not compatible with Rails 2 as of version 0.5. If you want to use
35
- Rails 2, please use the 0.4-stable branch on GitHub.
38
+ As of version 1.0, CarrierWave requires Rails 4.0 or higher and Ruby 2.0
39
+ or higher. If you're on Rails 3, you should use v0.11.0.
36
40
 
37
41
  ## Getting Started
38
42
 
@@ -100,24 +104,89 @@ automatically be stored when the record is saved.
100
104
 
101
105
  ```ruby
102
106
  u = User.new
103
- u.avatar = params[:file]
104
- u.avatar = File.open('somewhere')
107
+ u.avatar = params[:file] # Assign a file like this, or
108
+
109
+ # like this
110
+ File.open('somewhere') do |f|
111
+ u.avatar = f
112
+ end
113
+
105
114
  u.save!
106
115
  u.avatar.url # => '/url/to/file.png'
107
116
  u.avatar.current_path # => 'path/to/file.png'
108
- u.avatar.identifier # => 'file.png'
117
+ u.avatar_identifier # => 'file.png'
109
118
  ```
110
119
 
120
+ **Note**: `u.avatar` will never return nil, even if there is no photo associated to it.
121
+ To check if a photo was saved to the model, use `u.avatar.file.nil?` instead.
122
+
111
123
  ### DataMapper, Mongoid, Sequel
112
124
 
113
125
  Other ORM support has been extracted into separate gems:
114
126
 
115
127
  * [carrierwave-datamapper](https://github.com/carrierwaveuploader/carrierwave-datamapper)
116
128
  * [carrierwave-mongoid](https://github.com/carrierwaveuploader/carrierwave-mongoid)
117
- * [carrierwave-sequel](https://github.com/jnicklas/carrierwave-sequel)
129
+ * [carrierwave-sequel](https://github.com/carrierwaveuploader/carrierwave-sequel)
118
130
 
119
131
  There are more extensions listed in [the wiki](https://github.com/carrierwaveuploader/carrierwave/wiki)
120
132
 
133
+ ## Multiple file uploads
134
+
135
+ CarrierWave also has convenient support for multiple file upload fields.
136
+
137
+ ### ActiveRecord
138
+
139
+ Add a column which can store an array. This could be an array column or a JSON
140
+ column for example. Your choice depends on what your database supports. For
141
+ example, create a migration like this:
142
+
143
+
144
+ #### For databases with ActiveRecord json data type support (e.g. PostgreSQL, MySQL)
145
+
146
+ rails g migration add_avatars_to_users avatars:json
147
+ rake db:migrate
148
+
149
+ #### For database without ActiveRecord json data type support (e.g. SQLite)
150
+
151
+ rails g migration add_avatars_to_users avatars:string
152
+ rake db:migrate
153
+
154
+ __Note__: JSON datatype doesn't exists in SQLite adapter, that's why you can use a string datatype which will be serialized in model.
155
+
156
+ Open your model file and mount the uploader:
157
+
158
+
159
+ ```ruby
160
+ class User < ActiveRecord::Base
161
+ mount_uploaders :avatars, AvatarUploader
162
+ serialize :avatars, JSON # If you use SQLite, add this line.
163
+ end
164
+ ```
165
+
166
+ Make sure your file input fields are set up as multiple file fields. For
167
+ example in Rails you'll want to do something like this:
168
+
169
+ ```erb
170
+ <%= form.file_field :avatars, multiple: true %>
171
+ ```
172
+
173
+ Also, make sure your upload controller permits the multiple file upload attribute, *pointing to an empty array in a hash*. For example:
174
+
175
+ ```ruby
176
+ params.require(:user).permit(:email, :first_name, :last_name, {avatars: []})
177
+ ```
178
+
179
+ Now you can select multiple files in the upload dialog (e.g. SHIFT+SELECT), and they will
180
+ automatically be stored when the record is saved.
181
+
182
+ ```ruby
183
+ u = User.new(params[:user])
184
+ u.save!
185
+ u.avatars[0].url # => '/url/to/file.png'
186
+ u.avatars[0].current_path # => 'path/to/file.png'
187
+ u.avatars[0].identifier # => 'file.png'
188
+ ```
189
+
121
190
  ## Changing the storage directory
122
191
 
123
192
  In order to change where uploaded files are put, just override the `store_dir`
@@ -146,85 +215,69 @@ end
146
215
 
147
216
  ## Securing uploads
148
217
 
149
- Certain file might be dangerous if uploaded to the wrong location, such as php
150
- files or other script files. CarrierWave allows you to specify a white-list of
151
- allowed extensions.
218
+ Certain files might be dangerous if uploaded to the wrong location, such as PHP
219
+ files or other script files. CarrierWave allows you to specify a whitelist of
220
+ allowed extensions or content types.
152
221
 
153
222
  If you're mounting the uploader, uploading a file with the wrong extension will
154
223
  make the record invalid instead. Otherwise, an error is raised.
155
224
 
156
225
  ```ruby
157
226
  class MyUploader < CarrierWave::Uploader::Base
158
- def extension_white_list
227
+ def extension_whitelist
159
228
  %w(jpg jpeg gif png)
160
229
  end
161
230
  end
162
231
  ```
163
232
 
164
- ### CVE-2016-3714 (ImageTragick)
165
- This version of CarrierWave has the ability to mitigate CVE-2016-3714. However, you **MUST** set a `content_type_whitelist` in your uploaders for this protection to be effective, and you **MUST** either disable ImageMagick's default SVG delegate or use the RSVG delegate for SVG processing.
166
-
167
- A valid whitelist that will restrict your uploader to images only, and mitigate the CVE is:
233
+ The same thing could be done using content types.
234
+ Let's say we need an uploader that accepts only images. This can be done like this
168
235
 
169
236
  ```ruby
170
237
  class MyUploader < CarrierWave::Uploader::Base
171
238
  def content_type_whitelist
172
- [/image\//]
239
+ /image\//
173
240
  end
174
241
  end
175
242
  ```
176
243
 
177
- **WARNING**: A `content_type_whitelist` is the only form of whitelist or blacklist supported by CarrierWave that can effectively mitigate against CVE-2016-3714. Use of `extension_type_whitelist` will not inspect the file headers, and thus still leaves your application open to the vulnerability.
244
+ You can use a blacklist to reject content types.
245
+ Let's say we need an uploader that reject JSON files. This can be done like this
178
246
 
247
+ ```ruby
248
+ class NoJsonUploader < CarrierWave::Uploader::Base
249
+ def content_type_blacklist
250
+ ['application/text', 'application/json']
251
+ end
252
+ end
253
+ ```
179
254
 
180
255
  ### Filenames and unicode chars
181
256
 
182
257
  Another security issue you should care for is the file names (see
183
258
  [Ruby On Rails Security Guide](http://guides.rubyonrails.org/security.html#file-uploads)).
184
- By default, CarrierWave provides only English letters, arabic numerals and '-+_.' symbols as
259
+ By default, CarrierWave provides only English letters, arabic numerals and some symbols as
185
260
  white-listed characters in the file name. If you want to support local scripts (Cyrillic letters, letters with diacritics and so on), you
186
261
  have to override `sanitize_regexp` method. It should return regular expression which would match
187
262
  all *non*-allowed symbols.
188
263
 
189
- With Ruby 1.9 and higher you can simply write (as it has [Oniguruma](http://oniguruma.rubyforge.org/oniguruma/)
190
- built-in):
191
-
192
264
  ```ruby
193
265
  CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/
194
266
  ```
195
267
 
196
- With Ruby 1.8 you have to manually specify all character ranges. For example, for files which may
197
- contain Russian letters:
198
-
199
- ```ruby
200
- CarrierWave::SanitizedFile.sanitize_regexp = /[^a-zA-Zа-яА-ЯёЁ0-9\.\-\+_]/u
201
- ```
202
-
203
268
  Also make sure that allowing non-latin characters won't cause a compatibility issue with a third-party
204
269
  plugins or client-side software.
205
270
 
206
271
  ## Setting the content type
207
272
 
208
- If you care about the content type of your files and notice that it's not being set
209
- as expected, you can configure your uploaders to use `CarrierWave::MimeTypes`.
210
- This adds a dependency on the [mime-types](http://rubygems.org/gems/mime-types) gem,
211
- but is recommended when using fog, and fog already has a dependency on mime-types.
212
-
213
- ```ruby
214
- require 'carrierwave/processing/mime_types'
215
-
216
- class MyUploader < CarrierWave::Uploader::Base
217
- include CarrierWave::MimeTypes
218
-
219
- process :set_content_type
220
- end
221
- ```
273
+ As of v0.11.0, the `mime-types` gem is a runtime dependency and the content type is set automatically.
274
+ You no longer need to do this manually.
222
275
 
223
276
  ## Adding versions
224
277
 
225
278
  Often you'll want to add different versions of the same file. The classic example is image thumbnails. There is built in support for this*:
226
279
 
227
- *Note: You must have Imagemagick and MiniMagick installed to do image resizing. MiniMagick is a Ruby interface for Imagemagick which is a C program. This is why MiniMagick fails on 'bundle install' without Imagemagick installed.
280
+ *Note:* You must have Imagemagick and MiniMagick installed to do image resizing. MiniMagick is a Ruby interface for Imagemagick which is a C program. This is why MiniMagick fails on 'bundle install' without Imagemagick installed.
228
281
 
229
282
  Some documentation refers to RMagick instead of MiniMagick but MiniMagick is recommended.
230
283
 
@@ -238,10 +291,10 @@ $ brew install imagemagick
238
291
  class MyUploader < CarrierWave::Uploader::Base
239
292
  include CarrierWave::MiniMagick
240
293
 
241
- process :resize_to_fit => [800, 800]
294
+ process resize_to_fit: [800, 800]
242
295
 
243
296
  version :thumb do
244
- process :resize_to_fill => [200,200]
297
+ process resize_to_fill: [200,200]
245
298
  end
246
299
 
247
300
  end
@@ -283,11 +336,11 @@ properties within the model or based on the picture itself.
283
336
  ```ruby
284
337
  class MyUploader < CarrierWave::Uploader::Base
285
338
 
286
- version :human, :if => :is_human?
287
- version :monkey, :if => :is_monkey?
288
- version :banner, :if => :is_landscape?
339
+ version :human, if: :is_human?
340
+ version :monkey, if: :is_monkey?
341
+ version :banner, if: :is_landscape?
289
342
 
290
- protected
343
+ private
291
344
 
292
345
  def is_human? picture
293
346
  model.can_program?(:ruby)
@@ -321,7 +374,7 @@ class MyUploader < CarrierWave::Uploader::Base
321
374
  process resize_to_fill: [280, 280]
322
375
  end
323
376
 
324
- version :small_thumb, :from_version => :thumb do
377
+ version :small_thumb, from_version: :thumb do
325
378
  process resize_to_fill: [20, 20]
326
379
  end
327
380
 
@@ -340,7 +393,7 @@ file, just add a hidden field called `avatar_cache` (don't forget to add it to
340
393
  the attr_accessible list as necessary). In Rails, this would look like this:
341
394
 
342
395
  ```erb
343
- <%= form_for @user, :html => {:multipart => true} do |f| %>
396
+ <%= form_for @user, html: { multipart: true } do |f| %>
344
397
  <p>
345
398
  <label>My Avatar</label>
346
399
  <%= f.file_field :avatar %>
@@ -353,7 +406,7 @@ It might be a good idea to show the user that a file has been uploaded, in the
353
406
  case of images, a small thumbnail would be a good indicator:
354
407
 
355
408
  ```erb
356
- <%= form_for @user, :html => {:multipart => true} do |f| %>
409
+ <%= form_for @user, html: { multipart: true } do |f| %>
357
410
  <p>
358
411
  <label>My Avatar</label>
359
412
  <%= image_tag(@user.avatar_url) if @user.avatar? %>
@@ -369,7 +422,7 @@ If you want to remove a previously uploaded file on a mounted uploader, you can
369
422
  easily add a checkbox to the form which will remove the file when checked.
370
423
 
371
424
  ```erb
372
- <%= form_for @user, :html => {:multipart => true} do |f| %>
425
+ <%= form_for @user, html: { multipart: true } do |f| %>
373
426
  <p>
374
427
  <label>My Avatar</label>
375
428
  <%= image_tag(@user.avatar_url) if @user.avatar? %>
@@ -400,7 +453,7 @@ via a URL. CarrierWave makes this simple, just add the appropriate attribute to
400
453
  form and you're good to go:
401
454
 
402
455
  ```erb
403
- <%= form_for @user, :html => {:multipart => true} do |f| %>
456
+ <%= form_for @user, html: { multipart: true } do |f| %>
404
457
  <p>
405
458
  <label>My Avatar URL:</label>
406
459
  <%= image_tag(@user.avatar_url) if @user.avatar? %>
@@ -422,7 +475,7 @@ this easily by overriding the `default_url` method in your uploader:
422
475
 
423
476
  ```ruby
424
477
  class MyUploader < CarrierWave::Uploader::Base
425
- def default_url
478
+ def default_url(*args)
426
479
  "/images/fallback/" + [version_name, "default.png"].compact.join('_')
427
480
  end
428
481
  end
@@ -432,7 +485,7 @@ Or if you are using the Rails asset pipeline:
432
485
 
433
486
  ```ruby
434
487
  class MyUploader < CarrierWave::Uploader::Base
435
- def default_url
488
+ def default_url(*args)
436
489
  ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
437
490
  end
438
491
  end
@@ -459,7 +512,7 @@ instance.recreate_versions!(:thumb, :large)
459
512
  Or on a mounted uploader:
460
513
 
461
514
  ```ruby
462
- User.all.each do |user|
515
+ User.find_each do |user|
463
516
  user.avatar.recreate_versions!
464
517
  end
465
518
  ```
@@ -467,7 +520,7 @@ end
467
520
  Note: `recreate_versions!` will throw an exception on records without an image. To avoid this, scope the records to those with images or check if an image exists within the block. If you're using ActiveRecord, recreating versions for a user avatar might look like this:
468
521
 
469
522
  ```ruby
470
- User.all.each do |user|
523
+ User.find_each do |user|
471
524
  user.avatar.recreate_versions! if user.avatar?
472
525
  end
473
526
  ```
@@ -497,6 +550,16 @@ If you're using Rails, create an initializer for this:
497
550
 
498
551
  config/initializers/carrierwave.rb
499
552
 
553
+ If you want CarrierWave to fail noisily in development, you can change these configs in your environment file:
554
+
555
+ ```ruby
556
+ CarrierWave.configure do |config|
557
+ config.ignore_integrity_errors = false
558
+ config.ignore_processing_errors = false
559
+ config.ignore_download_errors = false
560
+ end
561
+ ```
562
+
500
563
 
501
564
  ## Testing with CarrierWave
502
565
 
@@ -527,31 +590,37 @@ require 'carrierwave/test/matchers'
527
590
  describe MyUploader do
528
591
  include CarrierWave::Test::Matchers
529
592
 
593
+ let(:user) { double('user') }
594
+ let(:uploader) { MyUploader.new(user, :avatar) }
595
+
530
596
  before do
531
597
  MyUploader.enable_processing = true
532
- @uploader = MyUploader.new(@user, :avatar)
533
- @uploader.store!(File.open(path_to_file))
598
+ File.open(path_to_file) { |f| uploader.store!(f) }
534
599
  end
535
600
 
536
601
  after do
537
602
  MyUploader.enable_processing = false
538
- @uploader.remove!
603
+ uploader.remove!
539
604
  end
540
605
 
541
606
  context 'the thumb version' do
542
- it "should scale down a landscape image to be exactly 64 by 64 pixels" do
543
- @uploader.thumb.should have_dimensions(64, 64)
607
+ it "scales down a landscape image to be exactly 64 by 64 pixels" do
608
+ expect(uploader.thumb).to have_dimensions(64, 64)
544
609
  end
545
610
  end
546
611
 
547
612
  context 'the small version' do
548
- it "should scale down a landscape image to fit within 200 by 200 pixels" do
549
- @uploader.small.should be_no_larger_than(200, 200)
613
+ it "scales down a landscape image to fit within 200 by 200 pixels" do
614
+ expect(uploader.small).to be_no_larger_than(200, 200)
550
615
  end
551
616
  end
552
617
 
553
- it "should make the image readable only to the owner and not executable" do
554
- @uploader.should have_permissions(0600)
618
+ it "makes the image readable only to the owner and not executable" do
619
+ expect(uploader).to have_permissions(0600)
620
+ end
621
+
622
+ it "has the correct format" do
623
+ expect(uploader).to be_format('png')
555
624
  end
556
625
  end
557
626
  ```
@@ -563,31 +632,42 @@ Processing can be enabled for a single version by setting the processing flag on
563
632
  @uploader.thumb.enable_processing = true
564
633
  ```
565
634
 
635
+ ## Fog
636
+
637
+ If you want to use fog you must add in your CarrierWave initializer the
638
+ following lines
639
+
640
+ ```ruby
641
+ config.fog_provider = 'fog' # 'fog/aws' etc. Defaults to 'fog'
642
+ config.fog_credentials = { ... } # Provider specific credentials
643
+ ```
644
+
566
645
  ## Using Amazon S3
567
646
 
568
- [Fog](http://github.com/fog/fog) is used to support Amazon S3. Ensure you have it in your Gemfile:
647
+ [Fog AWS](http://github.com/fog/fog-aws) is used to support Amazon S3. Ensure you have it in your Gemfile:
569
648
 
570
649
  ```ruby
571
- gem "fog", "~> 1.3.1"
650
+ gem "fog-aws"
572
651
  ```
573
652
 
574
653
  You'll need to provide your fog_credentials and a fog_directory (also known as a bucket) in an initializer.
575
- For the sake of performance it is assumed that the directory already exists, so please create it if need be.
654
+ For the sake of performance it is assumed that the directory already exists, so please create it if it needs to be.
576
655
  You can also pass in additional options, as documented fully in lib/carrierwave/storage/fog.rb. Here's a full example:
577
656
 
578
657
  ```ruby
579
658
  CarrierWave.configure do |config|
659
+ config.fog_provider = 'fog/aws' # required
580
660
  config.fog_credentials = {
581
- :provider => 'AWS', # required
582
- :aws_access_key_id => 'xxx', # required
583
- :aws_secret_access_key => 'yyy', # required
584
- :region => 'eu-west-1', # optional, defaults to 'us-east-1'
585
- :host => 's3.example.com', # optional, defaults to nil
586
- :endpoint => 'https://s3.example.com:8080' # optional, defaults to nil
661
+ provider: 'AWS', # required
662
+ aws_access_key_id: 'xxx', # required
663
+ aws_secret_access_key: 'yyy', # required
664
+ region: 'eu-west-1', # optional, defaults to 'us-east-1'
665
+ host: 's3.example.com', # optional, defaults to nil
666
+ endpoint: 'https://s3.example.com:8080' # optional, defaults to nil
587
667
  }
588
- config.fog_directory = 'name_of_directory' # required
589
- config.fog_public = false # optional, defaults to true
590
- config.fog_attributes = {'Cache-Control'=>'max-age=315576000'} # optional, defaults to {}
668
+ config.fog_directory = 'name_of_directory' # required
669
+ config.fog_public = false # optional, defaults to true
670
+ config.fog_attributes = { cache_control: "public, max-age=#{365.day.to_i}" } # optional, defaults to {}
591
671
  end
592
672
  ```
593
673
 
@@ -616,11 +696,12 @@ Using a US-based account:
616
696
 
617
697
  ```ruby
618
698
  CarrierWave.configure do |config|
699
+ config.fog_provider = "fog/rackspace/storage" # optional, defaults to "fog"
619
700
  config.fog_credentials = {
620
- :provider => 'Rackspace',
621
- :rackspace_username => 'xxxxxx',
622
- :rackspace_api_key => 'yyyyyy',
623
- :rackspace_region => :ord # optional, defaults to :dfw
701
+ provider: 'Rackspace',
702
+ rackspace_username: 'xxxxxx',
703
+ rackspace_api_key: 'yyyyyy',
704
+ rackspace_region: :ord # optional, defaults to :dfw
624
705
  }
625
706
  config.fog_directory = 'name_of_directory'
626
707
  end
@@ -630,12 +711,13 @@ Using a UK-based account:
630
711
 
631
712
  ```ruby
632
713
  CarrierWave.configure do |config|
714
+ config.fog_provider = "fog/rackspace/storage" # optional, defaults to "fog"
633
715
  config.fog_credentials = {
634
- :provider => 'Rackspace',
635
- :rackspace_username => 'xxxxxx',
636
- :rackspace_api_key => 'yyyyyy',
637
- :rackspace_auth_url => Fog::Rackspace::UK_AUTH_ENDPOINT,
638
- :rackspace_region => :lon
716
+ provider: 'Rackspace',
717
+ rackspace_username: 'xxxxxx',
718
+ rackspace_api_key: 'yyyyyy',
719
+ rackspace_auth_url: Fog::Rackspace::UK_AUTH_ENDPOINT,
720
+ rackspace_region: :lon
639
721
  }
640
722
  config.fog_directory = 'name_of_directory'
641
723
  end
@@ -662,25 +744,27 @@ the url to the file on Rackspace Cloud Files.
662
744
 
663
745
  ## Using Google Storage for Developers
664
746
 
665
- [Fog](http://github.com/fog/fog) is used to support Google Storage for Developers. Ensure you have it in your Gemfile:
747
+ [Fog](http://github.com/fog/fog-google) is used to support Google Storage for Developers. Ensure you have it in your Gemfile:
666
748
 
667
749
  ```ruby
668
- gem "fog"
750
+ gem "fog-google"
751
+ gem "google-api-client", "> 0.8.5", "< 0.9"
752
+ gem "mime-types"
669
753
  ```
670
754
 
671
755
  You'll need to configure a directory (also known as a bucket), access key id and secret access key in the initializer.
672
756
  For the sake of performance it is assumed that the directory already exists, so please create it if need be.
673
757
 
674
- Sign up [here](http://gs-signup-redirect.appspot.com/) and get your credentials [here](https://storage.cloud.google.com/m)
675
- under the section “Interoperable Access”.
758
+ Please read the [fog-google README](https://github.com/fog/fog-google/blob/master/README.md) on how to get credentials.
676
759
 
677
760
 
678
761
  ```ruby
679
762
  CarrierWave.configure do |config|
763
+ config.fog_provider = 'fog/google' # required
680
764
  config.fog_credentials = {
681
- :provider => 'Google',
682
- :google_storage_access_key_id => 'xxxxxx',
683
- :google_storage_secret_access_key => 'yyyyyy'
765
+ provider: 'Google',
766
+ google_storage_access_key_id: 'xxxxxx',
767
+ google_storage_secret_access_key: 'yyyyyy'
684
768
  }
685
769
  config.fog_directory = 'name_of_directory'
686
770
  end
@@ -697,6 +781,31 @@ end
697
781
  That's it! You can still use the `CarrierWave::Uploader#url` method to return
698
782
  the url to the file on Google.
699
783
 
784
+ ## Optimized Loading of Fog
785
+
786
+ Since Carrierwave doesn't know which parts of Fog you intend to use, it will just load the entire library (unless you use e.g. [`fog-aws`, `fog-google`] instead of fog proper). If you prefer to load fewer classes into your application, you need to load those parts of Fog yourself *before* loading CarrierWave in your Gemfile. Ex:
787
+
788
+ ```ruby
789
+ gem "fog", "~> 1.27", require: "fog/rackspace/storage"
790
+ gem "carrierwave"
791
+ ```
792
+
793
+ A couple of notes about versions:
794
+ * This functionality was introduced in Fog v1.20.
795
+ * This functionality is slated for CarrierWave v1.0.0.
796
+
797
+ If you're not relying on Gemfile entries alone and are requiring "carrierwave" anywhere, ensure you require "fog/rackspace/storage" before it. Ex:
798
+
799
+ ```ruby
800
+ require "fog/rackspace/storage"
801
+ require "carrierwave"
802
+ ```
803
+
804
+ Beware that this specific require is only needed when working with a fog provider that was not extracted to its own gem yet.
805
+ A list of the extracted providers can be found in the page of the `fog` organizations [here](https://github.com/fog).
806
+
807
+ When in doubt, inspect `Fog.constants` to see what has been loaded.
808
+
700
809
  ## Dynamic Asset Host
701
810
 
702
811
  The `asset_host` config property can be assigned a proc (or anything that responds to `call`) for generating the host dynamically. The proc-compliant object gets an instance of the current `CarrierWave::Storage::Fog::File` or `CarrierWave::SanitizedFile` as its only argument.
@@ -734,8 +843,8 @@ Convert will only work if the file has the same file extension, thus the use of
734
843
  class AvatarUploader < CarrierWave::Uploader::Base
735
844
  include CarrierWave::RMagick
736
845
 
737
- process :resize_to_fill => [200, 200]
738
- process :convert => 'png'
846
+ process resize_to_fill: [200, 200]
847
+ process convert: 'png'
739
848
 
740
849
  def filename
741
850
  super.chomp(File.extname(super)) + '.png' if original_filename.present?
@@ -767,7 +876,7 @@ for the RMagick processor.
767
876
  class AvatarUploader < CarrierWave::Uploader::Base
768
877
  include CarrierWave::MiniMagick
769
878
 
770
- process :resize_to_fill => [200, 200]
879
+ process resize_to_fill: [200, 200]
771
880
  end
772
881
  ```
773
882
 
@@ -787,14 +896,10 @@ details.
787
896
  Be sure to use mount_on to specify the correct column:
788
897
 
789
898
  ```ruby
790
- mount_uploader :avatar, AvatarUploader, :mount_on => :avatar_file_name
899
+ mount_uploader :avatar, AvatarUploader, mount_on: :avatar_file_name
791
900
  ```
792
901
 
793
- Unfortunately attachment_fu differs too much in philosophy for there to be a
794
- sensible compatibility mode. Patches for migrating from other solutions will be
795
- happily accepted.
796
-
797
- ## i18n
902
+ ## I18n
798
903
 
799
904
  The Active Record validations use the Rails i18n framework. Add these keys to
800
905
  your translations file:
@@ -805,8 +910,8 @@ errors:
805
910
  carrierwave_processing_error: "Cannot resize image."
806
911
  carrierwave_integrity_error: "Not an image."
807
912
  carrierwave_download_error: "Couldn't download image."
808
- extension_white_list_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
809
- extension_black_list_error: "You are not allowed to upload %{extension} files, prohibited types: %{prohibited_types}"
913
+ extension_whitelist_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
914
+ extension_blacklist_error: "You are not allowed to upload %{extension} files, prohibited types: %{prohibited_types}"
810
915
  ```
811
916
 
812
917
  ## Large files
@@ -822,6 +927,7 @@ class MyUploader < CarrierWave::Uploader::Base
822
927
  def move_to_cache
823
928
  true
824
929
  end
930
+
825
931
  def move_to_store
826
932
  true
827
933
  end
@@ -848,9 +954,10 @@ Will add these callbacks:
848
954
  ```ruby
849
955
  after_save :store_avatar!
850
956
  before_save :write_avatar_identifier
851
- after_commit :remove_avatar! :on => :destroy
852
- before_update :store_previous_model_for_avatar
853
- after_save :remove_previously_stored_avatar
957
+ after_commit :remove_avatar!, on: :destroy
958
+ after_commit :mark_remove_avatar_false, on: :update
959
+ after_save :store_previous_changes_for_avatar
960
+ after_commit :remove_previously_stored_avatar, on: :update
854
961
  ```
855
962
 
856
963
  If you want to skip any of these callbacks (eg. you want to keep the existing
@@ -860,7 +967,7 @@ avatar, even after uploading a new one), you can use ActiveRecord’s
860
967
  ```ruby
861
968
  class User
862
969
  mount_uploader :avatar, AvatarUploader
863
- skip_callback :save, :after, :remove_previously_stored_avatar
970
+ skip_callback :commit, :after, :remove_previously_stored_avatar
864
971
  end
865
972
  ```
866
973
 
@@ -870,7 +977,7 @@ See [CONTRIBUTING.md](https://github.com/carrierwaveuploader/carrierwave/blob/ma
870
977
 
871
978
  ## License
872
979
 
873
- Copyright (c) 2008-2013 Jonas Nicklas
980
+ Copyright (c) 2008-2015 Jonas Nicklas
874
981
 
875
982
  Permission is hereby granted, free of charge, to any person obtaining
876
983
  a copy of this software and associated documentation files (the
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module CarrierWave
4
2
  module Compatibility
5
3