carrierwave 0.8.0 → 0.9.0

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.

data/README.md CHANGED
@@ -3,19 +3,19 @@
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://secure.travis-ci.org/jnicklas/carrierwave.png)](http://travis-ci.org/jnicklas/carrierwave)
7
- [![Code Quality](https://codeclimate.com/badge.png)](https://codeclimate.com/github/jnicklas/carrierwave)
6
+ [![Build Status](https://secure.travis-ci.org/carrierwaveuploader/carrierwave.png)](http://travis-ci.org/carrierwaveuploader/carrierwave)
7
+ [![Code Climate](https://codeclimate.com/github/carrierwaveuploader/carrierwave.png)](https://codeclimate.com/github/carrierwaveuploader/carrierwave)
8
8
 
9
9
  ## Information
10
10
 
11
11
  * RDoc documentation [available on RubyDoc.info](http://rubydoc.info/gems/carrierwave/frames)
12
- * Source code [available on GitHub](http://github.com/jnicklas/carrierwave)
13
- * More information, known limitations, and how-tos [available on the wiki](https://github.com/jnicklas/carrierwave/wiki)
12
+ * Source code [available on GitHub](http://github.com/carrierwaveuploader/carrierwave)
13
+ * More information, known limitations, and how-tos [available on the wiki](https://github.com/carrierwaveuploader/carrierwave/wiki)
14
14
 
15
15
  ## Getting Help
16
16
 
17
17
  * Please ask the [Google Group](http://groups.google.com/group/carrierwave) for help if you have any questions.
18
- * Please report bugs on the [issue tracker](http://github.com/jnicklas/carrierwave/issues) but read the "getting help" section in the wiki first.
18
+ * Please report bugs on the [issue tracker](http://github.com/carrierwaveuploader/carrierwave/issues) but read the "getting help" section in the wiki first.
19
19
 
20
20
  ## Installation
21
21
 
@@ -80,11 +80,12 @@ need to require the relevant extension manually, e.g.:
80
80
  require 'carrierwave/orm/activerecord'
81
81
  ```
82
82
 
83
- Add a string column to the model you want to mount the uploader on:
83
+ Add a string column to the model you want to mount the uploader by creating
84
+ a migration:
84
85
 
85
- ```ruby
86
- add_column :users, :avatar, :string
87
- ```
86
+
87
+ rails g migration add_avatar_to_users avatar:string
88
+ rake db:migrate
88
89
 
89
90
  Open your model file and mount the uploader:
90
91
 
@@ -111,11 +112,11 @@ u.avatar.identifier # => 'file.png'
111
112
 
112
113
  Other ORM support has been extracted into separate gems:
113
114
 
114
- * [carrierwave-datamapper](https://github.com/jnicklas/carrierwave-datamapper)
115
- * [carrierwave-mongoid](https://github.com/jnicklas/carrierwave-mongoid)
116
- * [carrierwave-sequel](https://github.com/jnicklas/carrierwave-sequel)
115
+ * [carrierwave-datamapper](https://github.com/carrierwaveuploader/carrierwave-datamapper)
116
+ * [carrierwave-mongoid](https://github.com/carrierwaveuploader/carrierwave-mongoid)
117
+ * [carrierwave-sequel](https://github.com/carrierwaveuploader/carrierwave-sequel)
117
118
 
118
- There are more extensions listed in [the wiki](https://github.com/jnicklas/carrierwave/wiki)
119
+ There are more extensions listed in [the wiki](https://github.com/carrierwaveuploader/carrierwave/wiki)
119
120
 
120
121
  ## Changing the storage directory
121
122
 
@@ -133,6 +134,16 @@ end
133
134
  This works for the file storage as well as Amazon S3 and Rackspace Cloud Files.
134
135
  Define `store_dir` as `nil` if you'd like to store files at the root level.
135
136
 
137
+ If you store files outside the project root folder, you may want to define `cache_dir` in the same way:
138
+
139
+ ```ruby
140
+ class MyUploader < CarrierWave::Uploader::Base
141
+ def cache_dir
142
+ '/tmp/projectname-cache'
143
+ end
144
+ end
145
+ ```
146
+
136
147
  ## Securing uploads
137
148
 
138
149
  Certain file might be dangerous if uploaded to the wrong location, such as php
@@ -163,14 +174,14 @@ With Ruby 1.9 and higher you can simply write (as it has [Oniguruma](http://onig
163
174
  built-in):
164
175
 
165
176
  ```ruby
166
- CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/
177
+ CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/
167
178
  ```
168
179
 
169
180
  With Ruby 1.8 you have to manually specify all character ranges. For example, for files which may
170
181
  contain Russian letters:
171
182
 
172
183
  ```ruby
173
- CarrierWave::SanitizedFile.sanitize_regexp = /[^a-zA-Zа-яА-ЯёЁ0-9\.\-\+_]/u
184
+ CarrierWave::SanitizedFile.sanitize_regexp = /[^a-zA-Zа-яА-ЯёЁ0-9\.\-\+_]/u
174
185
  ```
175
186
 
176
187
  Also make sure that allowing non-latin characters won't cause a compatibility issue with a third-party
@@ -219,7 +230,7 @@ and cropped to exactly 200 by 200 pixels. The uploader could be used like this:
219
230
  uploader = AvatarUploader.new
220
231
  uploader.store!(my_file) # size: 1024x768
221
232
 
222
- uploader.url # => '/url/to/my_file.png' # size: 800x800
233
+ uploader.url # => '/url/to/my_file.png' # size: 800x600
223
234
  uploader.thumb.url # => '/url/to/thumb_my_file.png' # size: 200x200
224
235
  ```
225
236
 
@@ -367,6 +378,11 @@ form and you're good to go:
367
378
  <% end %>
368
379
  ```
369
380
 
381
+ If you're using ActiveRecord, CarrierWave will indicate invalid URLs and download
382
+ failures automatically with attribute validation errors. If you aren't, or you
383
+ disable CarrierWave's `validate_download` option, you'll need to handle those
384
+ errors yourself.
385
+
370
386
  ## Providing a default URL
371
387
 
372
388
  In many cases, especially when working with images, it might be a good idea to
@@ -381,13 +397,29 @@ class MyUploader < CarrierWave::Uploader::Base
381
397
  end
382
398
  ```
383
399
 
400
+ Or if you are using the Rails asset pipeline:
401
+
402
+ ```ruby
403
+ class MyUploader < CarrierWave::Uploader::Base
404
+ def default_url
405
+ ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
406
+ end
407
+ end
408
+ ```
409
+
384
410
  ## Recreating versions
385
411
 
386
412
  You might come to a situation where you want to retroactively change a version
387
- or add a new one. You can use the recreate_versions! method to recreate the
413
+ or add a new one. You can use the `recreate_versions!` method to recreate the
388
414
  versions from the base file. This uses a naive approach which will re-upload and
389
415
  process the specified version or all versions, if none is passed as an argument.
390
416
 
417
+ When you are generating random unique filenames you have to call `save!` on
418
+ the model after using `recreate_versions!`. This is necessary because
419
+ `recreate_versions!` doesn't save the new filename to the database. Calling
420
+ `save!` yourself will prevent that the database and file system are running
421
+ out of sync.
422
+
391
423
  ```ruby
392
424
  instance = MyUploader.new
393
425
  instance.recreate_versions!(:thumb, :large)
@@ -424,9 +456,8 @@ end
424
456
 
425
457
  If you're using Rails, create an initializer for this:
426
458
 
427
- ```ruby
428
- config/initializers/carrierwave.rb
429
- ```
459
+ config/initializers/carrierwave.rb
460
+
430
461
 
431
462
  ## Testing with CarrierWave
432
463
 
@@ -509,7 +540,7 @@ CarrierWave.configure do |config|
509
540
  :aws_access_key_id => 'xxx', # required
510
541
  :aws_secret_access_key => 'yyy', # required
511
542
  :region => 'eu-west-1', # optional, defaults to 'us-east-1'
512
- :hosts => 's3.example.com', # optional, defaults to nil
543
+ :host => 's3.example.com', # optional, defaults to nil
513
544
  :endpoint => 'https://s3.example.com:8080' # optional, defaults to nil
514
545
  }
515
546
  config.fog_directory = 'name_of_directory' # required
@@ -533,18 +564,36 @@ That's it! You can still use the `CarrierWave::Uploader#url` method to return th
533
564
  [Fog](http://github.com/fog/fog) is used to support Rackspace Cloud Files. Ensure you have it in your Gemfile:
534
565
 
535
566
  ```ruby
536
- gem "fog", "~> 1.3.1"
567
+ gem "fog", "~> 1.10.1"
537
568
  ```
538
569
 
539
570
  You'll need to configure a directory (also known as a container), username and API key in the initializer.
540
571
  For the sake of performance it is assumed that the directory already exists, so please create it if need be.
541
572
 
573
+ Using a US-based account:
574
+
575
+ ```ruby
576
+ CarrierWave.configure do |config|
577
+ config.fog_credentials = {
578
+ :provider => 'Rackspace',
579
+ :rackspace_username => 'xxxxxx',
580
+ :rackspace_api_key => 'yyyyyy',
581
+ :rackspace_region => :ord # optional, defaults to :dfw
582
+ }
583
+ config.fog_directory = 'name_of_directory'
584
+ end
585
+ ```
586
+
587
+ Using a UK-based account:
588
+
542
589
  ```ruby
543
590
  CarrierWave.configure do |config|
544
591
  config.fog_credentials = {
545
592
  :provider => 'Rackspace',
546
593
  :rackspace_username => 'xxxxxx',
547
- :rackspace_api_key => 'yyyyyy'
594
+ :rackspace_api_key => 'yyyyyy',
595
+ :rackspace_auth_url => Fog::Rackspace::UK_AUTH_ENDPOINT,
596
+ :rackspace_region => :lon
548
597
  }
549
598
  config.fog_directory = 'name_of_directory'
550
599
  end
@@ -741,7 +790,7 @@ This has only been tested with the local filesystem store.
741
790
 
742
791
  ## Contributing to CarrierWave
743
792
 
744
- See [CONTRIBUTING.md](https://github.com/jnicklas/carrierwave/blob/master/CONTRIBUTING.md)
793
+ See [CONTRIBUTING.md](https://github.com/carrierwaveuploader/carrierwave/blob/master/CONTRIBUTING.md)
745
794
 
746
795
  ## License
747
796
 
@@ -62,6 +62,7 @@ elsif defined?(Sinatra)
62
62
  end
63
63
  end
64
64
 
65
+ require "carrierwave/utilities"
65
66
  require "carrierwave/error"
66
67
  require "carrierwave/sanitized_file"
67
68
  require "carrierwave/mount"
@@ -0,0 +1,11 @@
1
+ cs:
2
+ errors:
3
+ messages:
4
+ carrierwave_processing_error: se nepodařilo zpracovat
5
+ carrierwave_integrity_error: není povolený typ souboru
6
+ carrierwave_download_error: nemůže být stažen
7
+ extension_white_list_error: "Není možné nahrávat %{extension} soubory, povolené typy: %{allowed_types}"
8
+ extension_black_list_error: "Není možné nahrávat %{extension} soubory, zakázané typy: %{prohibited_types}"
9
+ rmagick_processing_error: "Nepodařilo se upravit pomocí rmagick, možná se nejedná o obrázek? Hlášená Chyba: %{e}"
10
+ mime_types_processing_error: "Nepodařilo se upravit s MIME::Types, možná se nejedná o content-type? Hlášená Chyba: %{e}"
11
+ mini_magick_processing_error: "Nepodařilo se upravit pomocí MiniMagick, možná se nejedná o obrázek? Hlášená Chyba: %{e}"
@@ -0,0 +1,11 @@
1
+ de:
2
+ errors:
3
+ messages:
4
+ carrierwave_processing_error: konnte nicht verarbeitet werden
5
+ carrierwave_integrity_error: ist kein erlaubter Dateityp
6
+ carrierwave_download_error: konnte nicht heruntergeladen werden
7
+ extension_white_list_error: "Sie sind nicht berechtigt %{extension} Dateien hochzuladen, erlaubte Typen: %{allowed_types}"
8
+ extension_black_list_error: "Sie sind nicht berechtigt %{extension} Dateien hochzuladen, verbotene Typen: %{prohibited_types}"
9
+ rmagick_processing_error: "Verarbeitung mit rmagick fehlgeschlagen, vielleicht ist es kein Bild? Original Fehler: %{e}"
10
+ mime_types_processing_error: "Verarbeitung mit MIME::Types fehlgeschlagen, vielleicht kein gültiger content-type? Original Fehler: %{e}"
11
+ mini_magick_processing_error: "Verarbeitung mit MiniMagick fehlgeschlagen, vielleicht ist es kein Bild? Original Fehler: %{e}"
@@ -0,0 +1,11 @@
1
+ nl:
2
+ errors:
3
+ messages:
4
+ carrierwave_processing_error: kon niet worden verwerkt
5
+ carrierwave_integrity_error: is niet van een toegestaan bestandstype
6
+ carrierwave_download_error: kon niet gedownload worden
7
+ extension_white_list_error: "Het is niet toegestaan om %{extension} bestanden te uploaden; toegestane bestandstypes: %{allowed_types}"
8
+ extension_black_list_error: "Het is niet toegestaan om %{extension} bestanden te uploaden; verboden bestandstypes: %{prohibited_types}"
9
+ rmagick_processing_error: "Bewerking met rmagick is mislukt, misschien is het geen afbeelding? Originele foutmelding: %{e}"
10
+ mime_types_processing_error: "Verwerking van bestand met MIME::Types is mislukt, misschien is het geen geldig content-type? Originele foutmelding: %{e}"
11
+ mini_magick_processing_error: "Bewerking met MiniMagick is mislukt, misschien is het geen afbeelding? Originele foutmelding: %{e}"
@@ -0,0 +1,11 @@
1
+ sk:
2
+ errors:
3
+ messages:
4
+ carrierwave_processing_error: sa nepodarilo spracovať
5
+ carrierwave_integrity_error: nie je povolený typ súboru
6
+ carrierwave_download_error: nie je možné stiahnuť
7
+ extension_white_list_error: "Nie je možné nahrávať %{extension} súbory, povolené typy: %{allowed_types}"
8
+ extension_black_list_error: "Nie je možné nahrávať %{extension} súbory, zakázané typy: %{prohibited_types}"
9
+ rmagick_processing_error: "Nepodarilo sa upraviť pomocou rmagick, možno nejde o obrázok? Hlásená chyba: %{e}"
10
+ mime_types_processing_error: "Súbor sa nepodarilo spracovať pomocou MIME::Types, možno nejde o valídny content-type? Hlásená chyba: %{e}"
11
+ mini_magick_processing_error: "Nepodarilo sa upraviť pomocou MiniMagick, možno nejde o obrázok? Hlásená chyba: %{e}"
@@ -62,7 +62,7 @@ module CarrierWave
62
62
  #
63
63
  # @user.image.url # => '/some_url.png'
64
64
  #
65
- # It is also possible (but not recommended) to ommit the uploader, which
65
+ # It is also possible (but not recommended) to omit the uploader, which
66
66
  # will create an anonymous uploader class.
67
67
  #
68
68
  # Passing a block makes it possible to customize the uploader. This can be
@@ -57,7 +57,7 @@ module CarrierWave
57
57
  only = options && options[:only] && Array.wrap(options[:only]).map(&:to_s)
58
58
 
59
59
  self.class.uploaders.each do |column, uploader|
60
- if (!only && !except) || (only && only.include?(column.to_s)) || (except && !except.include?(column.to_s))
60
+ if (!only && !except) || (only && only.include?(column.to_s)) || (!only && except && !except.include?(column.to_s))
61
61
  hash[column.to_s] = _mounter(column).uploader.serializable_hash
62
62
  end
63
63
  end
@@ -104,6 +104,7 @@ module CarrierWave
104
104
  # image.convert(:png)
105
105
  #
106
106
  def convert(format)
107
+ @format = format
107
108
  manipulate! do |img|
108
109
  img.format(format.to_s.downcase)
109
110
  img = yield(img) if block_given?
@@ -257,11 +258,12 @@ module CarrierWave
257
258
  def manipulate!
258
259
  cache_stored_file! if !cached?
259
260
  image = ::MiniMagick::Image.open(current_path)
261
+ image.format(@format.to_s.downcase) if @format
260
262
  image = yield(image)
261
263
  image.write(current_path)
262
264
  ::MiniMagick::Image.open(current_path)
263
265
  rescue ::MiniMagick::Error, ::MiniMagick::Invalid => e
264
- raise CarrierWave::ProcessingError, I18n.translate(:"errors.messages.mini_magick_processing_error", :e => e)
266
+ raise CarrierWave::ProcessingError, I18n.translate(:"errors.messages.mini_magick_processing_error", :e => e, :default => I18n.translate(:"errors.messages.mini_magick_processing_error", :e => e, :locale => :en))
265
267
  end
266
268
 
267
269
  end # MiniMagick
@@ -116,6 +116,7 @@ module CarrierWave
116
116
  #
117
117
  def convert(format)
118
118
  manipulate!(:format => format)
119
+ @format = format
119
120
  end
120
121
 
121
122
  ##
@@ -214,7 +215,7 @@ module CarrierWave
214
215
  def resize_and_pad(width, height, background=:transparent, gravity=::Magick::CenterGravity)
215
216
  manipulate! do |img|
216
217
  img.resize_to_fit!(width, height)
217
- new_img = ::Magick::Image.new(width, height)
218
+ new_img = ::Magick::Image.new(width, height) { self.background_color = 'rgba(255,255,255,0)' }
218
219
  if background == :transparent
219
220
  filled = new_img.matte_floodfill(1, 1)
220
221
  else
@@ -333,14 +334,14 @@ module CarrierWave
333
334
  end
334
335
 
335
336
  write_block = create_info_block(options[:write])
336
- if options[:format]
337
- frames.write("#{options[:format]}:#{current_path}", &write_block)
337
+ if options[:format] || @format
338
+ frames.write("#{options[:format] || @format}:#{current_path}", &write_block)
338
339
  else
339
340
  frames.write(current_path, &write_block)
340
341
  end
341
342
  destroy_image(frames)
342
343
  rescue ::Magick::ImageMagickError => e
343
- raise CarrierWave::ProcessingError, I18n.translate(:"errors.messages.rmagick_processing_error", :e => e)
344
+ raise CarrierWave::ProcessingError, I18n.translate(:"errors.messages.rmagick_processing_error", :e => e, :default => I18n.translate(:"errors.messages.rmagick_processing_error", :e => e, :locale => :en))
344
345
  end
345
346
 
346
347
  private
@@ -30,7 +30,7 @@ module CarrierWave
30
30
  end
31
31
 
32
32
  ##
33
- # Returns the filename as is, without sanizting it.
33
+ # Returns the filename as is, without sanitizing it.
34
34
  #
35
35
  # === Returns
36
36
  #
@@ -153,11 +153,15 @@ module CarrierWave
153
153
  # [String] contents of the file
154
154
  #
155
155
  def read
156
- if is_path?
156
+ if @content
157
+ @content
158
+ elsif is_path?
157
159
  File.open(@file, "rb") {|file| file.read}
158
160
  else
159
161
  @file.rewind if @file.respond_to?(:rewind)
160
- @file.read
162
+ @content = @file.read
163
+ @file.close if @file.respond_to?(:close) && @file.respond_to?(:closed?) && !@file.closed?
164
+ @content
161
165
  end
162
166
  end
163
167
 
@@ -19,6 +19,7 @@ module CarrierWave
19
19
  # [:fog_public] (optional) public readability, defaults to true
20
20
  # [:fog_authenticated_url_expiration] (optional) time (in seconds) that authenticated urls
21
21
  # will be valid, when fog_public is false and provider is AWS or Google, defaults to 600
22
+ # [:fog_use_ssl_for_aws] (optional) #public_url will use https for the AWS generated URL]
22
23
  #
23
24
  #
24
25
  # AWS credentials contain the following keys:
@@ -103,6 +104,7 @@ module CarrierWave
103
104
  end
104
105
 
105
106
  class File
107
+ include CarrierWave::Utilities::Uri
106
108
 
107
109
  ##
108
110
  # Current local path to file
@@ -275,11 +277,12 @@ module CarrierWave
275
277
  # [NilClass] no public url available
276
278
  #
277
279
  def public_url
280
+ encoded_path = encode_path(path)
278
281
  if host = @uploader.asset_host
279
282
  if host.respond_to? :call
280
- "#{host.call(self)}/#{path}"
283
+ "#{host.call(self)}/#{encoded_path}"
281
284
  else
282
- "#{host}/#{path}"
285
+ "#{host}/#{encoded_path}"
283
286
  end
284
287
  else
285
288
  # AWS/Google optimized for speed over correctness
@@ -287,18 +290,19 @@ module CarrierWave
287
290
  when 'AWS'
288
291
  # check if some endpoint is set in fog_credentials
289
292
  if @uploader.fog_credentials.has_key?(:endpoint)
290
- "#{@uploader.fog_credentials[:endpoint]}/#{@uploader.fog_directory}/#{path}"
293
+ "#{@uploader.fog_credentials[:endpoint]}/#{@uploader.fog_directory}/#{encoded_path}"
291
294
  else
295
+ protocol = @uploader.fog_use_ssl_for_aws ? "https" : "http"
292
296
  # if directory is a valid subdomain, use that style for access
293
297
  if @uploader.fog_directory.to_s =~ /^(?:[a-z]|\d(?!\d{0,2}(?:\d{1,3}){3}$))(?:[a-z0-9\.]|(?![\-])|\-(?![\.])){1,61}[a-z0-9]$/
294
- "https://#{@uploader.fog_directory}.s3.amazonaws.com/#{path}"
298
+ "#{protocol}://#{@uploader.fog_directory}.s3.amazonaws.com/#{encoded_path}"
295
299
  else
296
300
  # directory is not a valid subdomain, so use path style for access
297
- "https://s3.amazonaws.com/#{@uploader.fog_directory}/#{path}"
301
+ "#{protocol}://s3.amazonaws.com/#{@uploader.fog_directory}/#{encoded_path}"
298
302
  end
299
303
  end
300
304
  when 'Google'
301
- "https://commondatastorage.googleapis.com/#{@uploader.fog_directory}/#{path}"
305
+ "https://commondatastorage.googleapis.com/#{@uploader.fog_directory}/#{encoded_path}"
302
306
  else
303
307
  # avoid a get by just using local reference
304
308
  directory.files.new(:key => path).public_url
@@ -334,7 +338,7 @@ module CarrierWave
334
338
  #
335
339
  def filename(options = {})
336
340
  if file_url = url(options)
337
- file_url.gsub(/.*\/(.*?$)/, '\1')
341
+ URI.decode(file_url).gsub(/.*\/(.*?$)/, '\1')
338
342
  end
339
343
  end
340
344
 
@@ -13,10 +13,10 @@ module CarrierWave
13
13
  #
14
14
  # === Returns
15
15
  #
16
- # [String] a cache id in the format YYYYMMDD-HHMM-PID-RND
16
+ # [String] a cache id in the format TIMEINT-PID-RND
17
17
  #
18
18
  def self.generate_cache_id
19
- Time.now.strftime('%Y%m%d-%H%M') + '-' + Process.pid.to_s + '-' + ("%04d" % rand(9999))
19
+ Time.now.utc.to_i.to_s + '-' + Process.pid.to_s + '-' + ("%04d" % rand(9999))
20
20
  end
21
21
 
22
22
  module Uploader
@@ -43,8 +43,8 @@ module CarrierWave
43
43
  #
44
44
  def clean_cached_files!(seconds=60*60*24)
45
45
  Dir.glob(File.expand_path(File.join(cache_dir, '*'), CarrierWave.root)).each do |dir|
46
- time = dir.scan(/(\d{4})(\d{2})(\d{2})-(\d{2})(\d{2})/).first.map { |t| t.to_i }
47
- time = Time.utc(*time)
46
+ time = dir.scan(/(\d+)-\d+-\d+/).first.map { |t| t.to_i }
47
+ time = Time.at(*time)
48
48
  if time < (Time.now.utc - seconds)
49
49
  FileUtils.rm_rf(dir)
50
50
  end
@@ -165,7 +165,7 @@ module CarrierWave
165
165
  alias_method :full_original_filename, :original_filename
166
166
 
167
167
  def cache_id=(cache_id)
168
- raise CarrierWave::InvalidParameter, "invalid cache id" unless cache_id =~ /\A[\d]{8}\-[\d]{4}\-[\d]+\-[\d]{4}\z/
168
+ raise CarrierWave::InvalidParameter, "invalid cache id" unless cache_id =~ /\A[\d]+\-[\d]+\-[\d]{4}\z/
169
169
  @cache_id = cache_id
170
170
  end
171
171
 
@@ -28,6 +28,7 @@ module CarrierWave
28
28
  add_config :fog_directory
29
29
  add_config :fog_public
30
30
  add_config :fog_authenticated_url_expiration
31
+ add_config :fog_use_ssl_for_aws
31
32
 
32
33
  # Mounting
33
34
  add_config :ignore_integrity_errors
@@ -96,7 +97,11 @@ module CarrierWave
96
97
  def #{name}
97
98
  value = @#{name} if instance_variable_defined?(:@#{name})
98
99
  value = self.class.#{name} unless instance_variable_defined?(:@#{name})
99
- value.instance_of?(Proc) ? value.call : value
100
+ if value.instance_of?(Proc)
101
+ value.arity >= 1 ? value.call(self) : value.call
102
+ else
103
+ value
104
+ end
100
105
  end
101
106
  RUBY
102
107
  end
@@ -121,6 +126,7 @@ module CarrierWave
121
126
  config.fog_credentials = {}
122
127
  config.fog_public = true
123
128
  config.fog_authenticated_url_expiration = 600
129
+ config.fog_use_ssl_for_aws = true
124
130
  config.store_dir = 'uploads'
125
131
  config.cache_dir = 'uploads/tmp'
126
132
  config.delete_tmp_file_after_storage = true
@@ -17,6 +17,10 @@ module CarrierWave
17
17
  end
18
18
 
19
19
  def original_filename
20
+ if file.meta.include? 'content-disposition'
21
+ match = file.meta['content-disposition'].match(/filename=(\"?)(.+)\1/)
22
+ return match[2] unless match.nil?
23
+ end
20
24
  File.basename(file.base_uri.path)
21
25
  end
22
26
 
@@ -70,7 +74,13 @@ module CarrierWave
70
74
  # [url (String)] The URL where the remote file is stored
71
75
  #
72
76
  def process_uri(uri)
73
- URI.parse(URI.escape(URI.unescape(uri)))
77
+ URI.parse(uri)
78
+ rescue URI::InvalidURIError
79
+ uri_parts = uri.split('?')
80
+ # regexp from Ruby's URI::Parser#regexp[:UNSAFE], with [] specifically removed
81
+ encoded_uri = URI.encode(uri_parts.shift, /[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,]/)
82
+ encoded_uri << '?' << URI.encode(uri_parts.join('?')) if uri_parts.any?
83
+ URI.parse(encoded_uri) rescue raise CarrierWave::DownloadError, "couldn't parse URL"
74
84
  end
75
85
 
76
86
  end # Download
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- require "active_support/json"
3
+ require "json"
4
4
  require "active_support/core_ext/hash"
5
5
 
6
6
  module CarrierWave
@@ -16,8 +16,8 @@ module CarrierWave
16
16
  Hash[mounted_as || "uploader", serializable_hash]
17
17
  end
18
18
 
19
- def to_json
20
- ActiveSupport::JSON.encode(as_json)
19
+ def to_json(options=nil)
20
+ JSON.generate(as_json)
21
21
  end
22
22
 
23
23
  def to_xml(options={})
@@ -5,6 +5,7 @@ module CarrierWave
5
5
  module Url
6
6
  extend ActiveSupport::Concern
7
7
  include CarrierWave::Uploader::Configuration
8
+ include CarrierWave::Utilities::Uri
8
9
 
9
10
  ##
10
11
  # === Parameters
@@ -19,7 +20,7 @@ module CarrierWave
19
20
  if file.respond_to?(:url) and not file.url.blank?
20
21
  file.method(:url).arity == 0 ? file.url : file.url(options)
21
22
  elsif file.respond_to?(:path)
22
- path = file.path.gsub(File.expand_path(root), '')
23
+ path = encode_path(file.path.gsub(File.expand_path(root), ''))
23
24
 
24
25
  if host = asset_host
25
26
  if host.respond_to? :call
@@ -68,6 +68,25 @@ module CarrierWave
68
68
  end
69
69
  RUBY
70
70
 
71
+ # Regardless of what is set in the parent uploader, do not enforce the
72
+ # move_to_cache config option on versions because it moves the original
73
+ # file to the version's target file.
74
+ #
75
+ # If you want to enforce this setting on versions, override this method
76
+ # in each version:
77
+ #
78
+ # version :thumb do
79
+ # def move_to_cache
80
+ # true
81
+ # end
82
+ # end
83
+ #
84
+ uploader.class_eval <<-RUBY
85
+ def move_to_cache
86
+ false
87
+ end
88
+ RUBY
89
+
71
90
  # Add the current version hash to class attribute :versions
72
91
  current_version = {}
73
92
  current_version[name] = {
@@ -125,6 +144,33 @@ module CarrierWave
125
144
  self.class.version_names.join('_').to_sym unless self.class.version_names.blank?
126
145
  end
127
146
 
147
+ ##
148
+ #
149
+ # === Parameters
150
+ #
151
+ # [name (#to_sym)] name of the version
152
+ #
153
+ # === Returns
154
+ #
155
+ # [Boolean] True when the version exists according to its :if condition
156
+ #
157
+ def version_exists?(name)
158
+ name = name.to_sym
159
+
160
+ return false unless self.class.versions.has_key?(name)
161
+
162
+ condition = self.class.versions[name][:options][:if]
163
+ if(condition)
164
+ if(condition.respond_to?(:call))
165
+ condition.call(self, :version => name, :file => file)
166
+ else
167
+ send(condition, file)
168
+ end
169
+ else
170
+ true
171
+ end
172
+ end
173
+
128
174
  ##
129
175
  # When given a version name as a parameter, will return the url for that version
130
176
  # This also works with nested versions.
@@ -153,7 +199,7 @@ module CarrierWave
153
199
  if (version = args.first) && version.respond_to?(:to_sym)
154
200
  raise ArgumentError, "Version #{version} doesn't exist!" if versions[version.to_sym].nil?
155
201
  # recursively proxy to version
156
- versions[version.to_sym].url(*args[1..-1])
202
+ versions[version.to_sym].url(*args[1..-1]) if version_exists?(version)
157
203
  elsif args.first
158
204
  super(args.first)
159
205
  else
@@ -190,16 +236,7 @@ module CarrierWave
190
236
 
191
237
  def active_versions
192
238
  versions.select do |name, uploader|
193
- condition = self.class.versions[name][:options][:if]
194
- if(condition)
195
- if(condition.respond_to?(:call))
196
- condition.call(self, :version => name, :file => file)
197
- else
198
- send(condition, file)
199
- end
200
- else
201
- true
202
- end
239
+ version_exists?(name)
203
240
  end
204
241
  end
205
242
 
@@ -240,7 +277,8 @@ module CarrierWave
240
277
 
241
278
  def store_versions!(new_file, versions=nil)
242
279
  if versions
243
- versions.each { |v| Hash[active_versions][v].store!(new_file) }
280
+ active = Hash[active_versions]
281
+ versions.each { |v| active[v].try(:store!, new_file) } unless active.empty?
244
282
  else
245
283
  active_versions.each { |name, v| v.store!(new_file) }
246
284
  end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ require 'carrierwave/utilities/uri'
4
+
5
+ module CarrierWave
6
+ module Utilities
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ module CarrierWave
4
+ module Utilities
5
+ module Uri
6
+
7
+ private
8
+ def encode_path(path)
9
+ # based on Ruby < 2.0's URI.encode
10
+ safe_string = URI::REGEXP::PATTERN::UNRESERVED + '\/'
11
+ unsafe = Regexp.new("[^#{safe_string}]", false)
12
+
13
+ path.to_s.gsub(unsafe) do
14
+ us = $&
15
+ tmp = ''
16
+ us.each_byte do |uc|
17
+ tmp << sprintf('%%%02X', uc)
18
+ end
19
+ tmp
20
+ end
21
+ end
22
+ end # Uri
23
+ end # Utilities
24
+ end # CarrierWave
@@ -1,3 +1,3 @@
1
1
  module CarrierWave
2
- VERSION = "0.8.0"
2
+ VERSION = "0.9.0"
3
3
  end
@@ -6,10 +6,6 @@ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
6
6
  # include CarrierWave::RMagick
7
7
  # include CarrierWave::MiniMagick
8
8
 
9
- # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
10
- # include Sprockets::Helpers::RailsHelper
11
- # include Sprockets::Helpers::IsolatedHelper
12
-
13
9
  # Choose what kind of storage to use for this uploader:
14
10
  storage :file
15
11
  # storage :fog
@@ -23,7 +19,7 @@ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
23
19
  # Provide a default URL as a default if there hasn't been a file uploaded:
24
20
  # def default_url
25
21
  # # For Rails 3.1+ asset pipeline compatibility:
26
- # # asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
22
+ # # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
27
23
  #
28
24
  # "/images/fallback/" + [version_name, "default.png"].compact.join('_')
29
25
  # end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-08 00:00:00.000000000 Z
12
+ date: 2013-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -44,29 +44,29 @@ dependencies:
44
44
  - !ruby/object:Gem::Version
45
45
  version: 3.2.0
46
46
  - !ruby/object:Gem::Dependency
47
- name: mysql2
47
+ name: json
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
51
  - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :development
53
+ version: '1.7'
54
+ type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  none: false
58
58
  requirements:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '1.7'
62
62
  - !ruby/object:Gem::Dependency
63
- name: rails
63
+ name: mysql2
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
67
  - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
- version: 3.2.0
69
+ version: '0'
70
70
  type: :development
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,39 +74,39 @@ dependencies:
74
74
  requirements:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
- version: 3.2.0
77
+ version: '0'
78
78
  - !ruby/object:Gem::Dependency
79
- name: cucumber
79
+ name: rails
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
83
- - - ~>
83
+ - - ! '>='
84
84
  - !ruby/object:Gem::Version
85
- version: 1.1.4
85
+ version: 3.2.0
86
86
  type: :development
87
87
  prerelease: false
88
88
  version_requirements: !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
91
- - - ~>
91
+ - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
- version: 1.1.4
93
+ version: 3.2.0
94
94
  - !ruby/object:Gem::Dependency
95
- name: json
95
+ name: cucumber
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
- - - ! '>='
99
+ - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: '0'
101
+ version: 1.3.2
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
- - - ! '>='
107
+ - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: '0'
109
+ version: 1.3.2
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: rspec
112
112
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +114,7 @@ dependencies:
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: 2.12.0
117
+ version: 2.13.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +122,7 @@ dependencies:
122
122
  requirements:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: 2.12.0
125
+ version: 2.13.0
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: sham_rack
128
128
  requirement: !ruby/object:Gem::Requirement
@@ -178,7 +178,7 @@ dependencies:
178
178
  requirements:
179
179
  - - ! '>='
180
180
  - !ruby/object:Gem::Version
181
- version: '0'
181
+ version: 3.6.0
182
182
  type: :development
183
183
  prerelease: false
184
184
  version_requirements: !ruby/object:Gem::Requirement
@@ -186,7 +186,7 @@ dependencies:
186
186
  requirements:
187
187
  - - ! '>='
188
188
  - !ruby/object:Gem::Version
189
- version: '0'
189
+ version: 3.6.0
190
190
  - !ruby/object:Gem::Dependency
191
191
  name: rmagick
192
192
  requirement: !ruby/object:Gem::Requirement
@@ -214,7 +214,11 @@ extra_rdoc_files:
214
214
  files:
215
215
  - lib/carrierwave/compatibility/paperclip.rb
216
216
  - lib/carrierwave/error.rb
217
+ - lib/carrierwave/locale/cs.yml
218
+ - lib/carrierwave/locale/de.yml
217
219
  - lib/carrierwave/locale/en.yml
220
+ - lib/carrierwave/locale/nl.yml
221
+ - lib/carrierwave/locale/sk.yml
218
222
  - lib/carrierwave/mount.rb
219
223
  - lib/carrierwave/orm/activerecord.rb
220
224
  - lib/carrierwave/processing/mime_types.rb
@@ -243,13 +247,15 @@ files:
243
247
  - lib/carrierwave/uploader/url.rb
244
248
  - lib/carrierwave/uploader/versions.rb
245
249
  - lib/carrierwave/uploader.rb
250
+ - lib/carrierwave/utilities/uri.rb
251
+ - lib/carrierwave/utilities.rb
246
252
  - lib/carrierwave/validations/active_model.rb
247
253
  - lib/carrierwave/version.rb
248
254
  - lib/carrierwave.rb
249
255
  - lib/generators/templates/uploader.rb
250
256
  - lib/generators/uploader_generator.rb
251
257
  - README.md
252
- homepage: https://github.com/jnicklas/carrierwave
258
+ homepage: https://github.com/carrierwaveuploader/carrierwave
253
259
  licenses: []
254
260
  post_install_message:
255
261
  rdoc_options:
@@ -275,4 +281,3 @@ signing_key:
275
281
  specification_version: 3
276
282
  summary: Ruby file upload library
277
283
  test_files: []
278
- has_rdoc: