carrierwave 0.11.0 → 1.0.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.

Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +225 -110
  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 +217 -176
  7. data/lib/carrierwave/mounter.rb +164 -0
  8. data/lib/carrierwave/orm/activerecord.rb +49 -20
  9. data/lib/carrierwave/processing/mini_magick.rb +64 -13
  10. data/lib/carrierwave/processing/rmagick.rb +31 -3
  11. data/lib/carrierwave/processing.rb +0 -1
  12. data/lib/carrierwave/sanitized_file.rb +37 -17
  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 +101 -29
  16. data/lib/carrierwave/storage.rb +0 -7
  17. data/lib/carrierwave/test/matchers.rb +77 -12
  18. data/lib/carrierwave/uploader/cache.rb +40 -26
  19. data/lib/carrierwave/uploader/callbacks.rb +0 -2
  20. data/lib/carrierwave/uploader/configuration.rb +48 -6
  21. data/lib/carrierwave/uploader/content_type_blacklist.rb +48 -0
  22. data/lib/carrierwave/uploader/content_type_whitelist.rb +48 -0
  23. data/lib/carrierwave/uploader/default_url.rb +3 -5
  24. data/lib/carrierwave/uploader/download.rb +10 -7
  25. data/lib/carrierwave/uploader/extension_blacklist.rb +14 -10
  26. data/lib/carrierwave/uploader/extension_whitelist.rb +12 -10
  27. data/lib/carrierwave/uploader/file_size.rb +41 -0
  28. data/lib/carrierwave/uploader/magic_mime_blacklist.rb +94 -0
  29. data/lib/carrierwave/uploader/magic_mime_whitelist.rb +94 -0
  30. data/lib/carrierwave/uploader/mountable.rb +7 -8
  31. data/lib/carrierwave/uploader/processing.rb +1 -3
  32. data/lib/carrierwave/uploader/proxy.rb +5 -7
  33. data/lib/carrierwave/uploader/remove.rb +0 -2
  34. data/lib/carrierwave/uploader/serialization.rb +1 -3
  35. data/lib/carrierwave/uploader/store.rb +5 -23
  36. data/lib/carrierwave/uploader/url.rb +1 -3
  37. data/lib/carrierwave/uploader/versions.rb +75 -82
  38. data/lib/carrierwave/uploader.rb +6 -2
  39. data/lib/carrierwave/utilities/uri.rb +4 -7
  40. data/lib/carrierwave/utilities.rb +0 -3
  41. data/lib/carrierwave/validations/active_model.rb +0 -2
  42. data/lib/carrierwave/version.rb +1 -1
  43. data/lib/carrierwave.rb +8 -10
  44. data/lib/generators/templates/uploader.rb +3 -5
  45. metadata +43 -81
  46. data/lib/carrierwave/locale/cs.yml +0 -11
  47. data/lib/carrierwave/locale/de.yml +0 -11
  48. data/lib/carrierwave/locale/el.yml +0 -11
  49. data/lib/carrierwave/locale/es.yml +0 -11
  50. data/lib/carrierwave/locale/fr.yml +0 -11
  51. data/lib/carrierwave/locale/ja.yml +0 -11
  52. data/lib/carrierwave/locale/nb.yml +0 -11
  53. data/lib/carrierwave/locale/nl.yml +0 -11
  54. data/lib/carrierwave/locale/pl.yml +0 -11
  55. data/lib/carrierwave/locale/pt-BR.yml +0 -11
  56. data/lib/carrierwave/locale/pt-PT.yml +0 -11
  57. data/lib/carrierwave/locale/ru.yml +0 -11
  58. data/lib/carrierwave/locale/sk.yml +0 -11
  59. data/lib/carrierwave/locale/tr.yml +0 -11
  60. data/lib/carrierwave/processing/mime_types.rb +0 -74
  61. data/lib/carrierwave/utilities/deprecation.rb +0 -18
@@ -0,0 +1,48 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module ContentTypeBlacklist
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before :cache, :check_content_type_blacklist!
8
+ end
9
+
10
+ ##
11
+ # Override this method in your uploader to provide a blacklist of files content types
12
+ # which are not allowed to be uploaded.
13
+ # Not only strings but Regexp are allowed as well.
14
+ #
15
+ # === Returns
16
+ #
17
+ # [NilClass, String, Regexp, Array[String, Regexp]] a blacklist of content types which are not allowed to be uploaded
18
+ #
19
+ # === Examples
20
+ #
21
+ # def content_type_blacklist
22
+ # %w(text/json application/json)
23
+ # end
24
+ #
25
+ # Basically the same, but using a Regexp:
26
+ #
27
+ # def content_type_blacklist
28
+ # [/(text|application)\/json/]
29
+ # end
30
+ #
31
+ def content_type_blacklist; end
32
+
33
+ private
34
+
35
+ def check_content_type_blacklist!(new_file)
36
+ content_type = new_file.content_type
37
+ if content_type_blacklist && blacklisted_content_type?(content_type)
38
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_blacklist_error", content_type: content_type)
39
+ end
40
+ end
41
+
42
+ def blacklisted_content_type?(content_type)
43
+ Array(content_type_blacklist).any? { |item| content_type =~ /#{item}/ }
44
+ end
45
+
46
+ end # ContentTypeBlacklist
47
+ end # Uploader
48
+ end # CarrierWave
@@ -0,0 +1,48 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module ContentTypeWhitelist
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before :cache, :check_content_type_whitelist!
8
+ end
9
+
10
+ ##
11
+ # Override this method in your uploader to provide a whitelist of files content types
12
+ # which are allowed to be uploaded.
13
+ # Not only strings but Regexp are allowed as well.
14
+ #
15
+ # === Returns
16
+ #
17
+ # [NilClass, String, Regexp, Array[String, Regexp]] a whitelist of content types which are allowed to be uploaded
18
+ #
19
+ # === Examples
20
+ #
21
+ # def content_type_whitelist
22
+ # %w(text/json application/json)
23
+ # end
24
+ #
25
+ # Basically the same, but using a Regexp:
26
+ #
27
+ # def content_type_whitelist
28
+ # [/(text|application)\/json/]
29
+ # end
30
+ #
31
+ def content_type_whitelist; end
32
+
33
+ private
34
+
35
+ def check_content_type_whitelist!(new_file)
36
+ content_type = new_file.content_type
37
+ if content_type_whitelist && !whitelisted_content_type?(content_type)
38
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.content_type_whitelist_error", content_type: content_type)
39
+ end
40
+ end
41
+
42
+ def whitelisted_content_type?(content_type)
43
+ Array(content_type_whitelist).any? { |item| content_type =~ /#{item}/ }
44
+ end
45
+
46
+ end # ContentTypeWhitelist
47
+ end # Uploader
48
+ end # CarrierWave
@@ -1,19 +1,17 @@
1
- # encoding: utf-8
2
-
3
1
  module CarrierWave
4
2
  module Uploader
5
3
  module DefaultUrl
6
4
 
7
5
  def url(*args)
8
- super || default_url
6
+ super || default_url(*args)
9
7
  end
10
8
 
11
9
  ##
12
10
  # Override this method in your uploader to provide a default url
13
11
  # in case no file has been cached/stored yet.
14
12
  #
15
- def default_url; end
13
+ def default_url(*args); end
16
14
 
17
15
  end # DefaultPath
18
16
  end # Uploader
19
- end # CarrierWave
17
+ end # CarrierWave
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require 'open-uri'
4
2
 
5
3
  module CarrierWave
@@ -12,8 +10,9 @@ module CarrierWave
12
10
  include CarrierWave::Uploader::Cache
13
11
 
14
12
  class RemoteFile
15
- def initialize(uri)
13
+ def initialize(uri, remote_headers = {})
16
14
  @uri = uri
15
+ @remote_headers = remote_headers
17
16
  end
18
17
 
19
18
  def original_filename
@@ -37,12 +36,15 @@ module CarrierWave
37
36
 
38
37
  def file
39
38
  if @file.blank?
40
- @file = Kernel.open(@uri.to_s)
39
+ headers = @remote_headers.
40
+ reverse_merge('User-Agent' => "CarrierWave/#{CarrierWave::VERSION}")
41
+
42
+ @file = Kernel.open(@uri.to_s, headers)
41
43
  @file = @file.is_a?(String) ? StringIO.new(@file) : @file
42
44
  end
43
45
  @file
44
46
 
45
- rescue Exception => e
47
+ rescue StandardError => e
46
48
  raise CarrierWave::DownloadError, "could not download file: #{e.message}"
47
49
  end
48
50
 
@@ -64,10 +66,11 @@ module CarrierWave
64
66
  # === Parameters
65
67
  #
66
68
  # [url (String)] The URL where the remote file is stored
69
+ # [remote_headers (Hash)] Request headers
67
70
  #
68
- def download!(uri)
71
+ def download!(uri, remote_headers = {})
69
72
  processed_uri = process_uri(uri)
70
- file = RemoteFile.new(processed_uri)
73
+ file = RemoteFile.new(processed_uri, remote_headers)
71
74
  raise CarrierWave::DownloadError, "trying to download a file which is not served over HTTP" unless file.http?
72
75
  cache!(file)
73
76
  end
@@ -4,7 +4,7 @@ module CarrierWave
4
4
  extend ActiveSupport::Concern
5
5
 
6
6
  included do
7
- before :cache, :check_blacklist!
7
+ before :cache, :check_extension_blacklist!
8
8
  end
9
9
 
10
10
  ##
@@ -16,32 +16,36 @@ module CarrierWave
16
16
  # the Regexp expression, also case insensitive.
17
17
  #
18
18
  # === Returns
19
-
20
- # [NilClass, Array[String,Regexp]] a black list of extensions which are prohibited to be uploaded
19
+
20
+ # [NilClass, String, Regexp, Array[String, Regexp]] a black list of extensions which are prohibited to be uploaded
21
21
  #
22
22
  # === Examples
23
23
  #
24
- # def extension_black_list
24
+ # def extension_blacklist
25
25
  # %w(swf tiff)
26
26
  # end
27
27
  #
28
28
  # Basically the same, but using a Regexp:
29
29
  #
30
- # def extension_black_list
30
+ # def extension_blacklist
31
31
  # [/swf/, 'tiff']
32
32
  # end
33
33
  #
34
-
35
- def extension_black_list; end
34
+
35
+ def extension_blacklist; end
36
36
 
37
37
  private
38
38
 
39
- def check_blacklist!(new_file)
39
+ def check_extension_blacklist!(new_file)
40
40
  extension = new_file.extension.to_s
41
- if extension_black_list and extension_black_list.detect { |item| extension =~ /\A#{item}\z/i }
42
- raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_black_list_error", :extension => new_file.extension.inspect, :prohibited_types => extension_black_list.join(", "))
41
+ if extension_blacklist && blacklisted_extension?(extension)
42
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_blacklist_error", extension: new_file.extension.inspect, prohibited_types: Array(extension_blacklist).join(", "))
43
43
  end
44
44
  end
45
+
46
+ def blacklisted_extension?(extension)
47
+ Array(extension_blacklist).any? { |item| extension =~ /\A#{item}\z/i }
48
+ end
45
49
  end
46
50
  end
47
51
  end
@@ -1,12 +1,10 @@
1
- # encoding: utf-8
2
-
3
1
  module CarrierWave
4
2
  module Uploader
5
3
  module ExtensionWhitelist
6
4
  extend ActiveSupport::Concern
7
5
 
8
6
  included do
9
- before :cache, :check_whitelist!
7
+ before :cache, :check_extension_whitelist!
10
8
  end
11
9
 
12
10
  ##
@@ -19,31 +17,35 @@ module CarrierWave
19
17
  #
20
18
  # === Returns
21
19
  #
22
- # [NilClass, Array[String,Regexp]] a white list of extensions which are allowed to be uploaded
20
+ # [NilClass, String, Regexp, Array[String, Regexp]] a white list of extensions which are allowed to be uploaded
23
21
  #
24
22
  # === Examples
25
23
  #
26
- # def extension_white_list
24
+ # def extension_whitelist
27
25
  # %w(jpg jpeg gif png)
28
26
  # end
29
27
  #
30
28
  # Basically the same, but using a Regexp:
31
29
  #
32
- # def extension_white_list
30
+ # def extension_whitelist
33
31
  # [/jpe?g/, 'gif', 'png']
34
32
  # end
35
33
  #
36
- def extension_white_list; end
34
+ def extension_whitelist; end
37
35
 
38
36
  private
39
37
 
40
- def check_whitelist!(new_file)
38
+ def check_extension_whitelist!(new_file)
41
39
  extension = new_file.extension.to_s
42
- if extension_white_list and not extension_white_list.detect { |item| extension =~ /\A#{item}\z/i }
43
- raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_white_list_error", :extension => new_file.extension.inspect, :allowed_types => extension_white_list.join(", "))
40
+ if extension_whitelist && !whitelisted_extension?(extension)
41
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.extension_whitelist_error", extension: new_file.extension.inspect, allowed_types: Array(extension_whitelist).join(", "))
44
42
  end
45
43
  end
46
44
 
45
+ def whitelisted_extension?(extension)
46
+ Array(extension_whitelist).any? { |item| extension =~ /\A#{item}\z/i }
47
+ end
48
+
47
49
  end # ExtensionWhitelist
48
50
  end # Uploader
49
51
  end # CarrierWave
@@ -0,0 +1,41 @@
1
+ module CarrierWave
2
+ module Uploader
3
+ module FileSize
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before :cache, :check_size!
8
+ end
9
+
10
+ ##
11
+ # Override this method in your uploader to provide a Range of Size which
12
+ # are allowed to be uploaded.
13
+ # === Returns
14
+ #
15
+ # [NilClass, Range] a size range which are permitted to be uploaded
16
+ #
17
+ # === Examples
18
+ #
19
+ # def size_range
20
+ # 3256...5748
21
+ # end
22
+ #
23
+ def size_range; end
24
+
25
+ private
26
+
27
+ def check_size!(new_file)
28
+ size = new_file.size
29
+ expected_size_range = size_range
30
+ if expected_size_range.is_a?(::Range)
31
+ if size < expected_size_range.min
32
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.min_size_error", :min_size => expected_size_range.min)
33
+ elsif size > expected_size_range.max
34
+ raise CarrierWave::IntegrityError, I18n.translate(:"errors.messages.max_size_error", :max_size => expected_size_range.max)
35
+ end
36
+ end
37
+ end
38
+
39
+ end # FileSize
40
+ end # Uploader
41
+ end # CarrierWave
@@ -0,0 +1,94 @@
1
+ module CarrierWave
2
+ module Uploader
3
+
4
+ ##
5
+ # This modules validates the content type of a file with the use of
6
+ # ruby-filemagic gem and a blacklist regular expression. If you want
7
+ # to use this, you'll need to require this file:
8
+ #
9
+ # require 'carrierwave/uploader/magic_mime_blacklist'
10
+ #
11
+ # And then include it in your uploader:
12
+ #
13
+ # class MyUploader < CarrierWave::Uploader::Base
14
+ # include CarrierWave::Uploader::MagicMimeBlacklist
15
+ #
16
+ # def blacklist_mime_type_pattern
17
+ # /image\//
18
+ # end
19
+ # end
20
+ #
21
+ module MagicMimeBlacklist
22
+ extend ActiveSupport::Concern
23
+
24
+ included do
25
+ begin
26
+ require "filemagic"
27
+ rescue LoadError => e
28
+ e.message << " (You may need to install the ruby-filemagic gem)"
29
+ raise e
30
+ end
31
+
32
+ before :cache, :check_blacklist_pattern!
33
+ end
34
+
35
+ ##
36
+ # Override this method in your uploader to provide a black list pattern (regexp)
37
+ # of content-types which are prohibited to be uploaded.
38
+ # Compares the file's content-type.
39
+ #
40
+ # === Returns
41
+ #
42
+ # [Regexp] a black list regexp to match the content_type
43
+ #
44
+ # === Examples
45
+ #
46
+ # def blacklist_mime_type_pattern
47
+ # /(text|application)\/json/
48
+ # end
49
+ #
50
+ def blacklist_mime_type_pattern; end
51
+
52
+ private
53
+
54
+ def check_blacklist_pattern!(new_file)
55
+ return if blacklist_mime_type_pattern.nil?
56
+
57
+ content_type = extract_content_type(new_file)
58
+
59
+ if content_type.match(blacklist_mime_type_pattern)
60
+ raise CarrierWave::IntegrityError,
61
+ I18n.translate(:"errors.messages.mime_type_pattern_black_list_error",
62
+ :content_type => content_type)
63
+ end
64
+ end
65
+
66
+ ##
67
+ # Extracts the content type of the given file
68
+ #
69
+ # === Returns
70
+ #
71
+ # [String] the extracted content type
72
+ #
73
+ def extract_content_type(new_file)
74
+ content_type = nil
75
+
76
+ File.open(new_file.path) do |fd|
77
+ data = fd.read(1024) || ""
78
+ content_type = filemagic.buffer(data)
79
+ end
80
+
81
+ content_type
82
+ end
83
+
84
+ ##
85
+ # FileMagic object with the MAGIC_MIME_TYPE flag set
86
+ #
87
+ # @return [FileMagic] a filemagic object
88
+ def filemagic
89
+ @filemagic ||= FileMagic.new(FileMagic::MAGIC_MIME_TYPE)
90
+ end
91
+
92
+ end # MagicMimeblackList
93
+ end # Uploader
94
+ end # CarrierWave
@@ -0,0 +1,94 @@
1
+ module CarrierWave
2
+ module Uploader
3
+
4
+ ##
5
+ # This modules validates the content type of a file with the use of
6
+ # ruby-filemagic gem and a whitelist regular expression. If you want
7
+ # to use this, you'll need to require this file:
8
+ #
9
+ # require 'carrierwave/uploader/magic_mime_whitelist'
10
+ #
11
+ # And then include it in your uploader:
12
+ #
13
+ # class MyUploader < CarrierWave::Uploader::Base
14
+ # include CarrierWave::Uploader::MagicMimeWhitelist
15
+ #
16
+ # def whitelist_mime_type_pattern
17
+ # /image\//
18
+ # end
19
+ # end
20
+ #
21
+ module MagicMimeWhitelist
22
+ extend ActiveSupport::Concern
23
+
24
+ included do
25
+ begin
26
+ require "filemagic"
27
+ rescue LoadError => e
28
+ e.message << " (You may need to install the ruby-filemagic gem)"
29
+ raise e
30
+ end
31
+
32
+ before :cache, :check_whitelist_pattern!
33
+ end
34
+
35
+ ##
36
+ # Override this method in your uploader to provide a white list pattern (regexp)
37
+ # of content-types which are allowed to be uploaded.
38
+ # Compares the file's content-type.
39
+ #
40
+ # === Returns
41
+ #
42
+ # [Regexp] a white list regexp to match the content_type
43
+ #
44
+ # === Examples
45
+ #
46
+ # def whitelist_mime_type_pattern
47
+ # /(text|application)\/json/
48
+ # end
49
+ #
50
+ def whitelist_mime_type_pattern; end
51
+
52
+ private
53
+
54
+ def check_whitelist_pattern!(new_file)
55
+ return if whitelist_mime_type_pattern.nil?
56
+
57
+ content_type = extract_content_type(new_file)
58
+
59
+ if !content_type.match(whitelist_mime_type_pattern)
60
+ raise CarrierWave::IntegrityError,
61
+ I18n.translate(:"errors.messages.mime_type_pattern_white_list_error",
62
+ :content_type => content_type)
63
+ end
64
+ end
65
+
66
+ ##
67
+ # Extracts the content type of the given file
68
+ #
69
+ # === Returns
70
+ #
71
+ # [String] the extracted content type
72
+ #
73
+ def extract_content_type(new_file)
74
+ content_type = nil
75
+
76
+ File.open(new_file.path) do |fd|
77
+ data = fd.read(1024) || ""
78
+ content_type = filemagic.buffer(data)
79
+ end
80
+
81
+ content_type
82
+ end
83
+
84
+ ##
85
+ # FileMagic object with the MAGIC_MIME_TYPE flag set
86
+ #
87
+ # @return [FileMagic] a filemagic object
88
+ def filemagic
89
+ @filemagic ||= FileMagic.new(FileMagic::MAGIC_MIME_TYPE)
90
+ end
91
+
92
+ end # MagicMimeWhiteList
93
+ end # Uploader
94
+ end # CarrierWave
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module CarrierWave
4
2
  module Uploader
5
3
  module Mountable
@@ -7,13 +5,14 @@ module CarrierWave
7
5
  attr_reader :model, :mounted_as
8
6
 
9
7
  ##
10
- # If a model is given as the first parameter, it will be stored in the uploader, and
11
- # available throught +#model+. Likewise, mounted_as stores the name of the column
12
- # where this instance of the uploader is mounted. These values can then be used inside
13
- # your uploader.
8
+ # If a model is given as the first parameter, it will be stored in the
9
+ # uploader, and available through +#model+. Likewise, mounted_as stores
10
+ # the name of the column where this instance of the uploader is mounted.
11
+ # These values can then be used inside your uploader.
14
12
  #
15
- # If you do not wish to mount your uploaders with the ORM extensions in -more then you
16
- # can override this method inside your uploader. Just be sure to call +super+
13
+ # If you do not wish to mount your uploaders with the ORM extensions in
14
+ # -more then you can override this method inside your uploader. Just be
15
+ # sure to call +super+
17
16
  #
18
17
  # === Parameters
19
18
  #
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module CarrierWave
4
2
  module Uploader
5
3
  module Processing
@@ -11,7 +9,7 @@ module CarrierWave
11
9
  class_attribute :processors, :instance_writer => false
12
10
  self.processors = []
13
11
 
14
- after :cache, :process!
12
+ before :cache, :process!
15
13
  end
16
14
 
17
15
  module ClassMethods
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module CarrierWave
4
2
  module Uploader
5
3
  module Proxy
@@ -19,7 +17,7 @@ module CarrierWave
19
17
  # [String] the path where the file is currently located.
20
18
  #
21
19
  def current_path
22
- file.path if file.respond_to?(:path)
20
+ file.try(:path)
23
21
  end
24
22
 
25
23
  alias_method :path, :current_path
@@ -32,7 +30,7 @@ module CarrierWave
32
30
  # [String] uniquely identifies a file
33
31
  #
34
32
  def identifier
35
- storage.identifier if storage.respond_to?(:identifier)
33
+ storage.try(:identifier)
36
34
  end
37
35
 
38
36
  ##
@@ -43,7 +41,7 @@ module CarrierWave
43
41
  # [String] contents of the file
44
42
  #
45
43
  def read
46
- file.read if file.respond_to?(:read)
44
+ file.try(:read)
47
45
  end
48
46
 
49
47
  ##
@@ -54,7 +52,7 @@ module CarrierWave
54
52
  # [Integer] size of the file
55
53
  #
56
54
  def size
57
- file.respond_to?(:size) ? file.size : 0
55
+ file.try(:size) || 0
58
56
  end
59
57
 
60
58
  ##
@@ -80,7 +78,7 @@ module CarrierWave
80
78
  # [String] content type of the file
81
79
  #
82
80
  def content_type
83
- file.respond_to?(:content_type) ? file.content_type : nil
81
+ file.try(:content_type)
84
82
  end
85
83
 
86
84
  end # Proxy
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module CarrierWave
4
2
  module Uploader
5
3
  module Remove
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  require "json"
4
2
  require "active_support/core_ext/hash"
5
3
 
@@ -13,7 +11,7 @@ module CarrierWave
13
11
  end
14
12
 
15
13
  def as_json(options=nil)
16
- Hash[mounted_as || "uploader", serializable_hash]
14
+ serializable_hash
17
15
  end
18
16
 
19
17
  def to_json(options=nil)
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module CarrierWave
4
2
  module Uploader
5
3
  module Store
@@ -54,35 +52,19 @@ module CarrierWave
54
52
  #
55
53
  def store!(new_file=nil)
56
54
  cache!(new_file) if new_file && ((@cache_id != parent_cache_id) || @cache_id.nil?)
57
- if @file and @cache_id
55
+ if !cache_only and @file and @cache_id
58
56
  with_callbacks(:store, new_file) do
59
57
  new_file = storage.store!(@file)
60
- @file.delete if (delete_tmp_file_after_storage && ! move_to_store)
61
- delete_cache_id
58
+ if delete_tmp_file_after_storage
59
+ @file.delete unless move_to_store
60
+ cache_storage.delete_dir!(cache_path(nil))
61
+ end
62
62
  @file = new_file
63
63
  @cache_id = nil
64
64
  end
65
65
  end
66
66
  end
67
67
 
68
- ##
69
- # Deletes a cache id (tmp dir in cache)
70
- #
71
- def delete_cache_id
72
- if @cache_id
73
- path = File.expand_path(File.join(cache_dir, @cache_id), CarrierWave.root)
74
- begin
75
- Dir.rmdir(path)
76
- rescue Errno::ENOENT
77
- # Ignore: path does not exist
78
- rescue Errno::ENOTDIR
79
- # Ignore: path is not a dir
80
- rescue Errno::ENOTEMPTY, Errno::EEXIST
81
- # Ignore: dir is not empty
82
- end
83
- end
84
- end
85
-
86
68
  ##
87
69
  # Retrieves the file from the storage.
88
70
  #
@@ -1,5 +1,3 @@
1
- # encoding: utf-8
2
-
3
1
  module CarrierWave
4
2
  module Uploader
5
3
  module Url
@@ -20,7 +18,7 @@ module CarrierWave
20
18
  if file.respond_to?(:url) and not file.url.blank?
21
19
  file.method(:url).arity == 0 ? file.url : file.url(options)
22
20
  elsif file.respond_to?(:path)
23
- path = encode_path(file.path.gsub(File.expand_path(root), ''))
21
+ path = encode_path(file.path.sub(File.expand_path(root), ''))
24
22
 
25
23
  if host = asset_host
26
24
  if host.respond_to? :call