carrierwave 1.0.0 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of carrierwave might be problematic. Click here for more details.
- checksums.yaml +5 -5
- data/README.md +53 -22
- data/lib/carrierwave/locale/en.yml +1 -1
- data/lib/carrierwave/mount.rb +4 -2
- data/lib/carrierwave/mounter.rb +1 -0
- data/lib/carrierwave/orm/activerecord.rb +5 -5
- data/lib/carrierwave/processing/mini_magick.rb +28 -8
- data/lib/carrierwave/processing/rmagick.rb +33 -6
- data/lib/carrierwave/sanitized_file.rb +11 -11
- data/lib/carrierwave/storage/file.rb +5 -1
- data/lib/carrierwave/storage/fog.rb +59 -14
- data/lib/carrierwave/uploader/cache.rb +1 -1
- data/lib/carrierwave/uploader/configuration.rb +6 -3
- data/lib/carrierwave/uploader/content_type_whitelist.rb +1 -1
- data/lib/carrierwave/uploader/download.rb +63 -15
- data/lib/carrierwave/uploader/extension_whitelist.rb +2 -1
- data/lib/carrierwave/uploader/file_size.rb +4 -2
- data/lib/carrierwave/uploader/processing.rb +9 -7
- data/lib/carrierwave/uploader/store.rb +9 -0
- data/lib/carrierwave/uploader/url.rb +2 -2
- data/lib/carrierwave/uploader/versions.rb +8 -1
- data/lib/carrierwave/uploader.rb +9 -0
- data/lib/carrierwave/utilities/uri.rb +2 -0
- data/lib/carrierwave/validations/active_model.rb +3 -3
- data/lib/carrierwave/version.rb +1 -1
- data/lib/carrierwave.rb +24 -0
- data/lib/generators/templates/uploader.rb +1 -3
- metadata +66 -27
- data/lib/carrierwave/uploader/magic_mime_blacklist.rb +0 -94
- data/lib/carrierwave/uploader/magic_mime_whitelist.rb +0 -94
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d5e6d1dd656203f5e14c43b75b807e793d623126006ddf8c5a4f9f4706faa750
|
4
|
+
data.tar.gz: 82281b939837f54716f580a1deb6397d87cc9bb867dc6a6938a4322d795500b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8eca3a53204f520d0cabf6e2384e6670cb634159e4b6c1e8d3915b6bab8473f21fb116047129b142a986588ea27401131d095186657770d7c31b03d6c929a1c9
|
7
|
+
data.tar.gz: 316797cffad6d2568e50929862cd80ba3e56c05d557f70f8631b66fc60ffd65fe5862afe4121a1e5e775e55a5f6c9a6c14414bce6a57deab2d12a8a127ed5b0d
|
data/README.md
CHANGED
@@ -4,8 +4,8 @@ This gem provides a simple and extremely flexible way to upload files from Ruby
|
|
4
4
|
It works well with Rack based web applications, such as Ruby on Rails.
|
5
5
|
|
6
6
|
[![Build Status](https://travis-ci.org/carrierwaveuploader/carrierwave.svg?branch=master)](http://travis-ci.org/carrierwaveuploader/carrierwave)
|
7
|
-
[![Code Climate](
|
8
|
-
[![
|
7
|
+
[![Code Climate](https://codeclimate.com/github/carrierwaveuploader/carrierwave.svg)](https://codeclimate.com/github/carrierwaveuploader/carrierwave)
|
8
|
+
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=carrierwave&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=carrierwave&package-manager=bundler&version-scheme=semver)
|
9
9
|
|
10
10
|
|
11
11
|
## Information
|
@@ -16,7 +16,7 @@ It works well with Rack based web applications, such as Ruby on Rails.
|
|
16
16
|
|
17
17
|
## Getting Help
|
18
18
|
|
19
|
-
* Please ask the community on [Stack Overflow](
|
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.
|
20
20
|
* Please report bugs on the [issue tracker](http://github.com/carrierwaveuploader/carrierwave/issues) but read the "getting help" section in the wiki first.
|
21
21
|
|
22
22
|
## Installation
|
@@ -24,7 +24,7 @@ It works well with Rack based web applications, such as Ruby on Rails.
|
|
24
24
|
Install the latest release:
|
25
25
|
|
26
26
|
```
|
27
|
-
$ gem install carrierwave
|
27
|
+
$ gem install carrierwave
|
28
28
|
```
|
29
29
|
|
30
30
|
In Rails, add it to your Gemfile:
|
@@ -89,7 +89,7 @@ a migration:
|
|
89
89
|
|
90
90
|
|
91
91
|
rails g migration add_avatar_to_users avatar:string
|
92
|
-
|
92
|
+
rails db:migrate
|
93
93
|
|
94
94
|
Open your model file and mount the uploader:
|
95
95
|
|
@@ -131,9 +131,6 @@ Other ORM support has been extracted into separate gems:
|
|
131
131
|
There are more extensions listed in [the wiki](https://github.com/carrierwaveuploader/carrierwave/wiki)
|
132
132
|
|
133
133
|
## Multiple file uploads
|
134
|
-
**Note:** You must specify using the master branch to enable this feature:
|
135
|
-
|
136
|
-
`gem 'carrierwave', github: 'carrierwaveuploader/carrierwave'`.
|
137
134
|
|
138
135
|
CarrierWave also has convenient support for multiple file upload fields.
|
139
136
|
|
@@ -144,17 +141,31 @@ column for example. Your choice depends on what your database supports. For
|
|
144
141
|
example, create a migration like this:
|
145
142
|
|
146
143
|
|
144
|
+
#### For databases with ActiveRecord json data type support (e.g. PostgreSQL, MySQL)
|
145
|
+
|
147
146
|
rails g migration add_avatars_to_users avatars:json
|
148
|
-
|
147
|
+
rails 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
|
+
rails 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.
|
149
155
|
|
150
156
|
Open your model file and mount the uploader:
|
151
157
|
|
158
|
+
|
152
159
|
```ruby
|
153
160
|
class User < ActiveRecord::Base
|
154
161
|
mount_uploaders :avatars, AvatarUploader
|
162
|
+
serialize :avatars, JSON # If you use SQLite, add this line.
|
155
163
|
end
|
156
164
|
```
|
157
165
|
|
166
|
+
Make sure that you mount the uploader with write (mount_uploaders) with `s` not (mount_uploader)
|
167
|
+
in order to avoid errors when uploading multiple files
|
168
|
+
|
158
169
|
Make sure your file input fields are set up as multiple file fields. For
|
159
170
|
example in Rails you'll want to do something like this:
|
160
171
|
|
@@ -293,14 +304,22 @@ end
|
|
293
304
|
```
|
294
305
|
|
295
306
|
When this uploader is used, an uploaded image would be scaled to be no larger
|
296
|
-
than 800 by 800 pixels.
|
297
|
-
|
307
|
+
than 800 by 800 pixels. The original aspect ratio will be kept.
|
308
|
+
A version called thumb is then created, which is scaled
|
309
|
+
to exactly 200 by 200 pixels.
|
310
|
+
|
311
|
+
If you would like to crop images to a specific height and width you
|
312
|
+
can use the alternative option of '''resize_to_fill'''. It will make sure
|
313
|
+
that the width and height specified are filled, only cropping
|
314
|
+
if the aspect ratio requires it.
|
315
|
+
|
316
|
+
The uploader could be used like this:
|
298
317
|
|
299
318
|
```ruby
|
300
319
|
uploader = AvatarUploader.new
|
301
320
|
uploader.store!(my_file) # size: 1024x768
|
302
321
|
|
303
|
-
uploader.url # => '/url/to/my_file.png' # size:
|
322
|
+
uploader.url # => '/url/to/my_file.png' # size: 800x800
|
304
323
|
uploader.thumb.url # => '/url/to/thumb_my_file.png' # size: 200x200
|
305
324
|
```
|
306
325
|
|
@@ -617,6 +636,8 @@ describe MyUploader do
|
|
617
636
|
end
|
618
637
|
```
|
619
638
|
|
639
|
+
If you're looking for minitest asserts, checkout [carrierwave_asserts](https://github.com/hcfairbanks/carrierwave_asserts).
|
640
|
+
|
620
641
|
Setting the enable_processing flag on an uploader will prevent any of the versions from processing as well.
|
621
642
|
Processing can be enabled for a single version by setting the processing flag on the version like so:
|
622
643
|
|
@@ -651,15 +672,16 @@ CarrierWave.configure do |config|
|
|
651
672
|
config.fog_provider = 'fog/aws' # required
|
652
673
|
config.fog_credentials = {
|
653
674
|
provider: 'AWS', # required
|
654
|
-
aws_access_key_id: 'xxx', # required
|
655
|
-
aws_secret_access_key: 'yyy', # required
|
675
|
+
aws_access_key_id: 'xxx', # required unless using use_iam_profile
|
676
|
+
aws_secret_access_key: 'yyy', # required unless using use_iam_profile
|
677
|
+
use_iam_profile: true, # optional, defaults to false
|
656
678
|
region: 'eu-west-1', # optional, defaults to 'us-east-1'
|
657
679
|
host: 's3.example.com', # optional, defaults to nil
|
658
680
|
endpoint: 'https://s3.example.com:8080' # optional, defaults to nil
|
659
681
|
}
|
660
|
-
config.fog_directory = '
|
661
|
-
config.fog_public = false
|
662
|
-
config.fog_attributes = {
|
682
|
+
config.fog_directory = 'name_of_bucket' # required
|
683
|
+
config.fog_public = false # optional, defaults to true
|
684
|
+
config.fog_attributes = { cache_control: "public, max-age=#{365.days.to_i}" } # optional, defaults to {}
|
663
685
|
end
|
664
686
|
```
|
665
687
|
|
@@ -740,7 +762,7 @@ the url to the file on Rackspace Cloud Files.
|
|
740
762
|
|
741
763
|
```ruby
|
742
764
|
gem "fog-google"
|
743
|
-
gem "google-api-client", "
|
765
|
+
gem "google-api-client", "> 0.8.5", "< 0.9"
|
744
766
|
gem "mime-types"
|
745
767
|
```
|
746
768
|
|
@@ -893,19 +915,28 @@ mount_uploader :avatar, AvatarUploader, mount_on: :avatar_file_name
|
|
893
915
|
|
894
916
|
## I18n
|
895
917
|
|
896
|
-
The Active Record validations use the Rails i18n framework. Add these keys to
|
918
|
+
The Active Record validations use the Rails `i18n` framework. Add these keys to
|
897
919
|
your translations file:
|
898
920
|
|
899
921
|
```yaml
|
900
922
|
errors:
|
901
923
|
messages:
|
902
|
-
carrierwave_processing_error:
|
903
|
-
carrierwave_integrity_error:
|
904
|
-
carrierwave_download_error:
|
924
|
+
carrierwave_processing_error: failed to be processed
|
925
|
+
carrierwave_integrity_error: is not of an allowed file type
|
926
|
+
carrierwave_download_error: could not be downloaded
|
905
927
|
extension_whitelist_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
|
906
928
|
extension_blacklist_error: "You are not allowed to upload %{extension} files, prohibited types: %{prohibited_types}"
|
929
|
+
content_type_whitelist_error: "You are not allowed to upload %{content_type} files, allowed types: %{allowed_types}"
|
930
|
+
content_type_blacklist_error: "You are not allowed to upload %{content_type} files"
|
931
|
+
rmagick_processing_error: "Failed to manipulate with rmagick, maybe it is not an image?"
|
932
|
+
mini_magick_processing_error: "Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: %{e}"
|
933
|
+
min_size_error: "File size should be greater than %{min_size}"
|
934
|
+
max_size_error: "File size should be less than %{max_size}"
|
907
935
|
```
|
908
936
|
|
937
|
+
The [`carrierwave-i18n`](https://github.com/carrierwaveuploader/carrierwave-i18n)
|
938
|
+
library adds support for additional locales.
|
939
|
+
|
909
940
|
## Large files
|
910
941
|
|
911
942
|
By default, CarrierWave copies an uploaded file twice, first copying the file into the cache, then
|
@@ -6,7 +6,7 @@ en:
|
|
6
6
|
carrierwave_download_error: could not be downloaded
|
7
7
|
extension_whitelist_error: "You are not allowed to upload %{extension} files, allowed types: %{allowed_types}"
|
8
8
|
extension_blacklist_error: "You are not allowed to upload %{extension} files, prohibited types: %{prohibited_types}"
|
9
|
-
content_type_whitelist_error: "You are not allowed to upload %{content_type} files"
|
9
|
+
content_type_whitelist_error: "You are not allowed to upload %{content_type} files, allowed types: %{allowed_types}"
|
10
10
|
content_type_blacklist_error: "You are not allowed to upload %{content_type} files"
|
11
11
|
rmagick_processing_error: "Failed to manipulate with rmagick, maybe it is not an image?"
|
12
12
|
mini_magick_processing_error: "Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: %{e}"
|
data/lib/carrierwave/mount.rb
CHANGED
@@ -186,7 +186,8 @@ module CarrierWave
|
|
186
186
|
end
|
187
187
|
|
188
188
|
def store_previous_changes_for_#{column}
|
189
|
-
|
189
|
+
attribute_changes = ::ActiveRecord.version.to_s.to_f >= 5.1 ? saved_changes : changes
|
190
|
+
@_previous_changes_for_#{column} = attribute_changes[_mounter(:#{column}).serialization_column]
|
190
191
|
end
|
191
192
|
|
192
193
|
def remove_previously_stored_#{column}
|
@@ -340,7 +341,8 @@ module CarrierWave
|
|
340
341
|
end
|
341
342
|
|
342
343
|
def store_previous_changes_for_#{column}
|
343
|
-
|
344
|
+
attribute_changes = ::ActiveRecord.version.to_s.to_f >= 5.1 ? saved_changes : changes
|
345
|
+
@_previous_changes_for_#{column} = attribute_changes[_mounter(:#{column}).serialization_column]
|
344
346
|
end
|
345
347
|
|
346
348
|
def remove_previously_stored_#{column}
|
data/lib/carrierwave/mounter.rb
CHANGED
@@ -15,7 +15,7 @@ module CarrierWave
|
|
15
15
|
class_eval <<-RUBY, __FILE__, __LINE__+1
|
16
16
|
def remote_#{column}_url=(url)
|
17
17
|
column = _mounter(:#{column}).serialization_column
|
18
|
-
|
18
|
+
__send__(:"\#{column}_will_change!")
|
19
19
|
super
|
20
20
|
end
|
21
21
|
RUBY
|
@@ -30,7 +30,7 @@ module CarrierWave
|
|
30
30
|
class_eval <<-RUBY, __FILE__, __LINE__+1
|
31
31
|
def remote_#{column}_urls=(url)
|
32
32
|
column = _mounter(:#{column}).serialization_column
|
33
|
-
|
33
|
+
__send__(:"\#{column}_will_change!")
|
34
34
|
super
|
35
35
|
end
|
36
36
|
RUBY
|
@@ -63,8 +63,8 @@ module CarrierWave
|
|
63
63
|
class_eval <<-RUBY, __FILE__, __LINE__+1
|
64
64
|
def #{column}=(new_file)
|
65
65
|
column = _mounter(:#{column}).serialization_column
|
66
|
-
if !(new_file.blank? &&
|
67
|
-
|
66
|
+
if !(new_file.blank? && __send__(:#{column}).blank?)
|
67
|
+
__send__(:"\#{column}_will_change!")
|
68
68
|
end
|
69
69
|
|
70
70
|
super
|
@@ -72,7 +72,7 @@ module CarrierWave
|
|
72
72
|
|
73
73
|
def remove_#{column}=(value)
|
74
74
|
column = _mounter(:#{column}).serialization_column
|
75
|
-
|
75
|
+
__send__(:"\#{column}_will_change!")
|
76
76
|
super
|
77
77
|
end
|
78
78
|
|
@@ -61,6 +61,13 @@ module CarrierWave
|
|
61
61
|
e.message << " (You may need to install the mini_magick gem)"
|
62
62
|
raise e
|
63
63
|
end
|
64
|
+
|
65
|
+
prepend Module.new {
|
66
|
+
def initialize(*)
|
67
|
+
super
|
68
|
+
@format = nil
|
69
|
+
end
|
70
|
+
}
|
64
71
|
end
|
65
72
|
|
66
73
|
module ClassMethods
|
@@ -127,6 +134,8 @@ module CarrierWave
|
|
127
134
|
# [MiniMagick::Image] additional manipulations to perform
|
128
135
|
#
|
129
136
|
def resize_to_limit(width, height, combine_options: {})
|
137
|
+
width = dimension_from width
|
138
|
+
height = dimension_from height
|
130
139
|
manipulate! do |img|
|
131
140
|
img.combine_options do |cmd|
|
132
141
|
cmd.resize "#{width}x#{height}>"
|
@@ -152,6 +161,8 @@ module CarrierWave
|
|
152
161
|
# [MiniMagick::Image] additional manipulations to perform
|
153
162
|
#
|
154
163
|
def resize_to_fit(width, height, combine_options: {})
|
164
|
+
width = dimension_from width
|
165
|
+
height = dimension_from height
|
155
166
|
manipulate! do |img|
|
156
167
|
img.combine_options do |cmd|
|
157
168
|
cmd.resize "#{width}x#{height}"
|
@@ -178,6 +189,8 @@ module CarrierWave
|
|
178
189
|
# [MiniMagick::Image] additional manipulations to perform
|
179
190
|
#
|
180
191
|
def resize_to_fill(width, height, gravity = 'Center', combine_options: {})
|
192
|
+
width = dimension_from width
|
193
|
+
height = dimension_from height
|
181
194
|
manipulate! do |img|
|
182
195
|
cols, rows = img[:dimensions]
|
183
196
|
img.combine_options do |cmd|
|
@@ -225,6 +238,8 @@ module CarrierWave
|
|
225
238
|
# [MiniMagick::Image] additional manipulations to perform
|
226
239
|
#
|
227
240
|
def resize_and_pad(width, height, background=:transparent, gravity='Center', combine_options: {})
|
241
|
+
width = dimension_from width
|
242
|
+
height = dimension_from height
|
228
243
|
manipulate! do |img|
|
229
244
|
img.combine_options do |cmd|
|
230
245
|
cmd.thumbnail "#{width}x#{height}>"
|
@@ -295,6 +310,7 @@ module CarrierWave
|
|
295
310
|
|
296
311
|
if @format
|
297
312
|
move_to = current_path.chomp(File.extname(current_path)) + ".#{@format}"
|
313
|
+
file.content_type = ::MIME::Types.type_for(move_to).first.to_s
|
298
314
|
file.move_to(move_to, permissions, directory_permissions)
|
299
315
|
end
|
300
316
|
|
@@ -303,8 +319,7 @@ module CarrierWave
|
|
303
319
|
image.destroy!
|
304
320
|
end
|
305
321
|
rescue ::MiniMagick::Error, ::MiniMagick::Invalid => e
|
306
|
-
|
307
|
-
message = I18n.translate(:"errors.messages.mini_magick_processing_error", :e => e, :default => default)
|
322
|
+
message = I18n.translate(:"errors.messages.mini_magick_processing_error", :e => e)
|
308
323
|
raise CarrierWave::ProcessingError, message
|
309
324
|
end
|
310
325
|
|
@@ -312,16 +327,21 @@ module CarrierWave
|
|
312
327
|
|
313
328
|
def append_combine_options(cmd, combine_options)
|
314
329
|
combine_options.each do |method, options|
|
315
|
-
|
330
|
+
if options.nil?
|
331
|
+
cmd.send(method)
|
332
|
+
else
|
333
|
+
cmd.send(method, options)
|
334
|
+
end
|
316
335
|
end
|
317
336
|
end
|
318
337
|
|
338
|
+
def dimension_from(value)
|
339
|
+
return value unless value.instance_of?(Proc)
|
340
|
+
value.arity >= 1 ? value.call(self) : value.call
|
341
|
+
end
|
342
|
+
|
319
343
|
def mini_magick_image
|
320
|
-
|
321
|
-
::MiniMagick::Image.open(url)
|
322
|
-
else
|
323
|
-
::MiniMagick::Image.open(current_path)
|
324
|
-
end
|
344
|
+
::MiniMagick::Image.read(read)
|
325
345
|
end
|
326
346
|
|
327
347
|
end # MiniMagick
|
@@ -67,6 +67,13 @@ module CarrierWave
|
|
67
67
|
e.message << " (You may need to install the rmagick gem)"
|
68
68
|
raise e
|
69
69
|
end
|
70
|
+
|
71
|
+
prepend Module.new {
|
72
|
+
def initialize(*)
|
73
|
+
super
|
74
|
+
@format = nil
|
75
|
+
end
|
76
|
+
}
|
70
77
|
end
|
71
78
|
|
72
79
|
module ClassMethods
|
@@ -133,6 +140,8 @@ module CarrierWave
|
|
133
140
|
# [Magick::Image] additional manipulations to perform
|
134
141
|
#
|
135
142
|
def resize_to_limit(width, height)
|
143
|
+
width = dimension_from width
|
144
|
+
height = dimension_from height
|
136
145
|
manipulate! do |img|
|
137
146
|
geometry = Magick::Geometry.new(width, height, 0, 0, Magick::GreaterGeometry)
|
138
147
|
new_img = img.change_geometry(geometry) do |new_width, new_height|
|
@@ -162,6 +171,8 @@ module CarrierWave
|
|
162
171
|
# [Magick::Image] additional manipulations to perform
|
163
172
|
#
|
164
173
|
def resize_to_fit(width, height)
|
174
|
+
width = dimension_from width
|
175
|
+
height = dimension_from height
|
165
176
|
manipulate! do |img|
|
166
177
|
img.resize_to_fit!(width, height)
|
167
178
|
img = yield(img) if block_given?
|
@@ -186,6 +197,8 @@ module CarrierWave
|
|
186
197
|
# [Magick::Image] additional manipulations to perform
|
187
198
|
#
|
188
199
|
def resize_to_fill(width, height, gravity=::Magick::CenterGravity)
|
200
|
+
width = dimension_from width
|
201
|
+
height = dimension_from height
|
189
202
|
manipulate! do |img|
|
190
203
|
img.crop_resized!(width, height, gravity)
|
191
204
|
img = yield(img) if block_given?
|
@@ -211,6 +224,8 @@ module CarrierWave
|
|
211
224
|
# [Magick::Image] additional manipulations to perform
|
212
225
|
#
|
213
226
|
def resize_and_pad(width, height, background=:transparent, gravity=::Magick::CenterGravity)
|
227
|
+
width = dimension_from width
|
228
|
+
height = dimension_from height
|
214
229
|
manipulate! do |img|
|
215
230
|
img.resize_to_fit!(width, height)
|
216
231
|
new_img = ::Magick::Image.new(width, height) { self.background_color = background == :transparent ? 'rgba(255,255,255,0)' : background.to_s }
|
@@ -338,7 +353,7 @@ module CarrierWave
|
|
338
353
|
frames = ::Magick::ImageList.new
|
339
354
|
|
340
355
|
image.each_with_index do |frame, index|
|
341
|
-
frame = yield
|
356
|
+
frame = yield(*[frame, index, options].take(block.arity)) if block_given?
|
342
357
|
frames << frame if frame
|
343
358
|
end
|
344
359
|
frames.append(true) if block_given?
|
@@ -348,6 +363,7 @@ module CarrierWave
|
|
348
363
|
if options[:format] || @format
|
349
364
|
frames.write("#{options[:format] || @format}:#{current_path}", &write_block)
|
350
365
|
move_to = current_path.chomp(File.extname(current_path)) + ".#{options[:format] || @format}"
|
366
|
+
file.content_type = ::MIME::Types.type_for(move_to).first.to_s
|
351
367
|
file.move_to(move_to, permissions, directory_permissions)
|
352
368
|
else
|
353
369
|
frames.write(current_path, &write_block)
|
@@ -355,24 +371,35 @@ module CarrierWave
|
|
355
371
|
|
356
372
|
destroy_image(frames)
|
357
373
|
rescue ::Magick::ImageMagickError => e
|
358
|
-
raise CarrierWave::ProcessingError, I18n.translate(:"errors.messages.rmagick_processing_error", :e => e
|
374
|
+
raise CarrierWave::ProcessingError, I18n.translate(:"errors.messages.rmagick_processing_error", :e => e)
|
359
375
|
end
|
360
376
|
|
361
377
|
private
|
362
378
|
|
363
379
|
def create_info_block(options)
|
364
380
|
return nil unless options
|
365
|
-
|
366
|
-
|
367
|
-
|
381
|
+
proc do |img|
|
382
|
+
options.each do |k, v|
|
383
|
+
if v.is_a?(String) && (matches = v.match(/^["'](.+)["']/))
|
384
|
+
ActiveSupport::Deprecation.warn "Passing quoted strings like #{v} to #manipulate! is deprecated, pass them without quoting."
|
385
|
+
v = matches[1]
|
386
|
+
end
|
387
|
+
img.public_send(:"#{k}=", v)
|
388
|
+
end
|
389
|
+
end
|
368
390
|
end
|
369
391
|
|
370
392
|
def destroy_image(image)
|
371
393
|
image.try(:destroy!)
|
372
394
|
end
|
373
395
|
|
396
|
+
def dimension_from(value)
|
397
|
+
return value unless value.instance_of?(Proc)
|
398
|
+
value.arity >= 1 ? value.call(self) : value.call
|
399
|
+
end
|
400
|
+
|
374
401
|
def rmagick_image
|
375
|
-
::Magick::Image.read
|
402
|
+
::Magick::Image.from_blob(self.read).first
|
376
403
|
end
|
377
404
|
|
378
405
|
end # RMagick
|
@@ -20,7 +20,7 @@ module CarrierWave
|
|
20
20
|
#
|
21
21
|
class SanitizedFile
|
22
22
|
|
23
|
-
|
23
|
+
attr_reader :file
|
24
24
|
|
25
25
|
class << self
|
26
26
|
attr_writer :sanitize_regexp
|
@@ -32,6 +32,7 @@ module CarrierWave
|
|
32
32
|
|
33
33
|
def initialize(file)
|
34
34
|
self.file = file
|
35
|
+
@content = nil
|
35
36
|
end
|
36
37
|
|
37
38
|
##
|
@@ -113,12 +114,11 @@ module CarrierWave
|
|
113
114
|
# [String, nil] the path where the file is located.
|
114
115
|
#
|
115
116
|
def path
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
end
|
117
|
+
return if @file.blank?
|
118
|
+
if is_path?
|
119
|
+
File.expand_path(@file)
|
120
|
+
elsif @file.respond_to?(:path) && !@file.path.blank?
|
121
|
+
File.expand_path(@file.path)
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
@@ -186,9 +186,9 @@ module CarrierWave
|
|
186
186
|
move!(new_path)
|
187
187
|
chmod!(new_path, permissions)
|
188
188
|
if keep_filename
|
189
|
-
self.file = {:tempfile => new_path, :filename => original_filename}
|
189
|
+
self.file = {:tempfile => new_path, :filename => original_filename, :content_type => content_type}
|
190
190
|
else
|
191
|
-
self.file = new_path
|
191
|
+
self.file = {:tempfile => new_path, :content_type => content_type}
|
192
192
|
end
|
193
193
|
self
|
194
194
|
end
|
@@ -197,7 +197,7 @@ module CarrierWave
|
|
197
197
|
#
|
198
198
|
def move!(new_path)
|
199
199
|
if exists?
|
200
|
-
FileUtils.mv(path, new_path) unless new_path
|
200
|
+
FileUtils.mv(path, new_path) unless File.identical?(new_path, path)
|
201
201
|
else
|
202
202
|
File.open(new_path, "wb") { |f| f.write(read) }
|
203
203
|
end
|
@@ -312,7 +312,7 @@ module CarrierWave
|
|
312
312
|
def mkdir!(path, directory_permissions)
|
313
313
|
options = {}
|
314
314
|
options[:mode] = directory_permissions if directory_permissions
|
315
|
-
FileUtils.mkdir_p(File.dirname(path), options) unless File.exist?(File.dirname(path))
|
315
|
+
FileUtils.mkdir_p(File.dirname(path), **options) unless File.exist?(File.dirname(path))
|
316
316
|
end
|
317
317
|
|
318
318
|
def chmod!(path, permissions)
|
@@ -7,6 +7,10 @@ module CarrierWave
|
|
7
7
|
# pretty much it.
|
8
8
|
#
|
9
9
|
class File < Abstract
|
10
|
+
def initialize(*)
|
11
|
+
super
|
12
|
+
@cache_called = nil
|
13
|
+
end
|
10
14
|
|
11
15
|
##
|
12
16
|
# Move the file to the uploader's store path.
|
@@ -62,7 +66,7 @@ module CarrierWave
|
|
62
66
|
#
|
63
67
|
def cache!(new_file)
|
64
68
|
new_file.move_to(::File.expand_path(uploader.cache_path, uploader.root), uploader.permissions, uploader.directory_permissions, true)
|
65
|
-
rescue Errno::EMLINK => e
|
69
|
+
rescue Errno::EMLINK, Errno::ENOSPC => e
|
66
70
|
raise(e) if @cache_called
|
67
71
|
@cache_called = true
|
68
72
|
|