carrierwave 0.5.1 → 0.5.4
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.
- data/README.rdoc +171 -58
- data/lib/carrierwave/compatibility/paperclip.rb +18 -18
- data/lib/carrierwave/mount.rb +7 -5
- data/lib/carrierwave/orm/activerecord.rb +10 -3
- data/lib/carrierwave/orm/datamapper.rb +1 -1
- data/lib/carrierwave/orm/sequel.rb +5 -5
- data/lib/carrierwave/processing/image_science.rb +25 -2
- data/lib/carrierwave/processing/mini_magick.rb +1 -0
- data/lib/carrierwave/processing/rmagick.rb +3 -2
- data/lib/carrierwave/sanitized_file.rb +15 -3
- data/lib/carrierwave/storage/cloud_files.rb +30 -10
- data/lib/carrierwave/storage/fog.rb +332 -0
- data/lib/carrierwave/storage/grid_fs.rb +6 -6
- data/lib/carrierwave/storage/s3.rb +17 -7
- data/lib/carrierwave/uploader/cache.rb +17 -3
- data/lib/carrierwave/uploader/callbacks.rb +11 -17
- data/lib/carrierwave/uploader/configuration.rb +53 -27
- data/lib/carrierwave/uploader/download.rb +16 -5
- data/lib/carrierwave/uploader/extension_whitelist.rb +14 -3
- data/lib/carrierwave/uploader/processing.rb +0 -1
- data/lib/carrierwave/uploader/url.rb +3 -2
- data/lib/carrierwave/uploader/versions.rb +16 -4
- data/lib/carrierwave/version.rb +1 -1
- data/lib/carrierwave.rb +9 -3
- data/lib/generators/templates/uploader.rb +2 -1
- metadata +155 -114
|
@@ -15,10 +15,14 @@ module CarrierWave
|
|
|
15
15
|
add_config :s3_cnamed
|
|
16
16
|
add_config :s3_headers
|
|
17
17
|
add_config :s3_region
|
|
18
|
+
add_config :s3_use_ssl
|
|
19
|
+
add_config :s3_authentication_timeout
|
|
18
20
|
add_config :cloud_files_username
|
|
19
21
|
add_config :cloud_files_api_key
|
|
20
22
|
add_config :cloud_files_container
|
|
21
23
|
add_config :cloud_files_cdn_host
|
|
24
|
+
add_config :cloud_files_auth_url
|
|
25
|
+
add_config :cloud_files_snet
|
|
22
26
|
add_config :grid_fs_connection
|
|
23
27
|
add_config :grid_fs_database
|
|
24
28
|
add_config :grid_fs_host
|
|
@@ -32,6 +36,14 @@ module CarrierWave
|
|
|
32
36
|
add_config :ensure_multipart_form
|
|
33
37
|
add_config :delete_tmp_file_after_storage
|
|
34
38
|
|
|
39
|
+
# fog
|
|
40
|
+
add_config :fog_attributes
|
|
41
|
+
add_config :fog_credentials
|
|
42
|
+
add_config :fog_directory
|
|
43
|
+
add_config :fog_host
|
|
44
|
+
add_config :fog_public
|
|
45
|
+
add_config :fog_authenticated_url_expiration
|
|
46
|
+
|
|
35
47
|
# Mounting
|
|
36
48
|
add_config :ignore_integrity_errors
|
|
37
49
|
add_config :ignore_processing_errors
|
|
@@ -39,33 +51,8 @@ module CarrierWave
|
|
|
39
51
|
add_config :validate_processing
|
|
40
52
|
add_config :mount_on
|
|
41
53
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
config.storage_engines = {
|
|
45
|
-
:file => "CarrierWave::Storage::File",
|
|
46
|
-
:s3 => "CarrierWave::Storage::S3",
|
|
47
|
-
:grid_fs => "CarrierWave::Storage::GridFS",
|
|
48
|
-
:right_s3 => "CarrierWave::Storage::RightS3",
|
|
49
|
-
:cloud_files => "CarrierWave::Storage::CloudFiles"
|
|
50
|
-
}
|
|
51
|
-
config.storage = :file
|
|
52
|
-
config.s3_headers = {}
|
|
53
|
-
config.s3_access_policy = :public_read
|
|
54
|
-
config.s3_region = 'us-east-1'
|
|
55
|
-
config.grid_fs_database = 'carrierwave'
|
|
56
|
-
config.grid_fs_host = 'localhost'
|
|
57
|
-
config.grid_fs_port = 27017
|
|
58
|
-
config.store_dir = 'uploads'
|
|
59
|
-
config.cache_dir = 'uploads/tmp'
|
|
60
|
-
config.delete_tmp_file_after_storage = true
|
|
61
|
-
config.ignore_integrity_errors = true
|
|
62
|
-
config.ignore_processing_errors = true
|
|
63
|
-
config.validate_integrity = true
|
|
64
|
-
config.validate_processing = true
|
|
65
|
-
config.root = CarrierWave.root
|
|
66
|
-
config.enable_processing = true
|
|
67
|
-
config.ensure_multipart_form = true
|
|
68
|
-
end
|
|
54
|
+
# set default values
|
|
55
|
+
reset_config
|
|
69
56
|
end
|
|
70
57
|
|
|
71
58
|
module ClassMethods
|
|
@@ -130,6 +117,45 @@ module CarrierWave
|
|
|
130
117
|
def configure
|
|
131
118
|
yield self
|
|
132
119
|
end
|
|
120
|
+
|
|
121
|
+
##
|
|
122
|
+
# sets configuration back to default
|
|
123
|
+
#
|
|
124
|
+
def reset_config
|
|
125
|
+
configure do |config|
|
|
126
|
+
config.permissions = 0644
|
|
127
|
+
config.storage_engines = {
|
|
128
|
+
:file => "CarrierWave::Storage::File",
|
|
129
|
+
:fog => "CarrierWave::Storage::Fog",
|
|
130
|
+
:s3 => "CarrierWave::Storage::S3",
|
|
131
|
+
:grid_fs => "CarrierWave::Storage::GridFS",
|
|
132
|
+
:right_s3 => "CarrierWave::Storage::RightS3",
|
|
133
|
+
:cloud_files => "CarrierWave::Storage::CloudFiles"
|
|
134
|
+
}
|
|
135
|
+
config.storage = :file
|
|
136
|
+
config.s3_headers = {}
|
|
137
|
+
config.s3_access_policy = :public_read
|
|
138
|
+
config.s3_region = 'us-east-1'
|
|
139
|
+
config.s3_authentication_timeout = 600
|
|
140
|
+
config.grid_fs_database = 'carrierwave'
|
|
141
|
+
config.grid_fs_host = 'localhost'
|
|
142
|
+
config.grid_fs_port = 27017
|
|
143
|
+
config.fog_attributes = {}
|
|
144
|
+
config.fog_credentials = {}
|
|
145
|
+
config.fog_public = true
|
|
146
|
+
config.fog_authenticated_url_expiration = 600
|
|
147
|
+
config.store_dir = 'uploads'
|
|
148
|
+
config.cache_dir = 'uploads/tmp'
|
|
149
|
+
config.delete_tmp_file_after_storage = true
|
|
150
|
+
config.ignore_integrity_errors = true
|
|
151
|
+
config.ignore_processing_errors = true
|
|
152
|
+
config.validate_integrity = true
|
|
153
|
+
config.validate_processing = true
|
|
154
|
+
config.root = CarrierWave.root
|
|
155
|
+
config.enable_processing = true
|
|
156
|
+
config.ensure_multipart_form = true
|
|
157
|
+
end
|
|
158
|
+
end
|
|
133
159
|
end
|
|
134
160
|
|
|
135
161
|
end
|
|
@@ -13,11 +13,11 @@ module CarrierWave
|
|
|
13
13
|
|
|
14
14
|
class RemoteFile
|
|
15
15
|
def initialize(uri)
|
|
16
|
-
@uri =
|
|
16
|
+
@uri = uri
|
|
17
17
|
end
|
|
18
18
|
|
|
19
19
|
def original_filename
|
|
20
|
-
File.basename(
|
|
20
|
+
File.basename(file.base_uri.path)
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
def respond_to?(*args)
|
|
@@ -52,13 +52,24 @@ module CarrierWave
|
|
|
52
52
|
#
|
|
53
53
|
def download!(uri)
|
|
54
54
|
unless uri.blank?
|
|
55
|
-
|
|
55
|
+
processed_uri = process_uri(uri)
|
|
56
|
+
file = RemoteFile.new(processed_uri)
|
|
56
57
|
raise CarrierWave::DownloadError, "trying to download a file which is not served over HTTP" unless file.http?
|
|
57
|
-
cache!(file)
|
|
58
|
+
cache!(file)
|
|
58
59
|
end
|
|
59
60
|
end
|
|
60
61
|
|
|
62
|
+
##
|
|
63
|
+
# Processes the given URL by parsing and escaping it. Public to allow overriding.
|
|
64
|
+
#
|
|
65
|
+
# === Parameters
|
|
66
|
+
#
|
|
67
|
+
# [url (String)] The URL where the remote file is stored
|
|
68
|
+
#
|
|
69
|
+
def process_uri(uri)
|
|
70
|
+
URI.parse(URI.escape(uri))
|
|
71
|
+
end
|
|
72
|
+
|
|
61
73
|
end # Download
|
|
62
74
|
end # Uploader
|
|
63
75
|
end # CarrierWave
|
|
64
|
-
|
|
@@ -11,11 +11,15 @@ module CarrierWave
|
|
|
11
11
|
|
|
12
12
|
##
|
|
13
13
|
# Override this method in your uploader to provide a white list of extensions which
|
|
14
|
-
# are allowed to be uploaded.
|
|
14
|
+
# are allowed to be uploaded. Compares the file's extension case insensitive.
|
|
15
|
+
# Furthermore, not only strings but Regexp are allowed as well.
|
|
16
|
+
#
|
|
17
|
+
# When using a Regexp in the white list, `\A` and `\z` are automatically added to
|
|
18
|
+
# the Regexp expression, also case insensitive.
|
|
15
19
|
#
|
|
16
20
|
# === Returns
|
|
17
21
|
#
|
|
18
|
-
# [NilClass, Array[String]] a white list of extensions which are allowed to be uploaded
|
|
22
|
+
# [NilClass, Array[String,Regexp]] a white list of extensions which are allowed to be uploaded
|
|
19
23
|
#
|
|
20
24
|
# === Examples
|
|
21
25
|
#
|
|
@@ -23,12 +27,19 @@ module CarrierWave
|
|
|
23
27
|
# %w(jpg jpeg gif png)
|
|
24
28
|
# end
|
|
25
29
|
#
|
|
30
|
+
# Basically the same, but using a Regexp:
|
|
31
|
+
#
|
|
32
|
+
# def extension_white_list
|
|
33
|
+
# [/jpe?g/, 'gif', 'png']
|
|
34
|
+
# end
|
|
35
|
+
#
|
|
26
36
|
def extension_white_list; end
|
|
27
37
|
|
|
28
38
|
private
|
|
29
39
|
|
|
30
40
|
def check_whitelist!(new_file)
|
|
31
|
-
|
|
41
|
+
extension = new_file.extension.to_s
|
|
42
|
+
if extension_white_list and not extension_white_list.detect { |item| extension =~ /\A#{item}\z/i }
|
|
32
43
|
raise CarrierWave::IntegrityError, "You are not allowed to upload #{new_file.extension.inspect} files, allowed types: #{extension_white_list.inspect}"
|
|
33
44
|
end
|
|
34
45
|
end
|
|
@@ -22,10 +22,11 @@ module CarrierWave
|
|
|
22
22
|
##
|
|
23
23
|
# === Returns
|
|
24
24
|
#
|
|
25
|
-
# [String] A JSON
|
|
25
|
+
# [String] A JSON serialization containing this uploader's URL(s)
|
|
26
26
|
#
|
|
27
27
|
def as_json(options = nil)
|
|
28
|
-
{ :url => url }
|
|
28
|
+
h = { :url => url }
|
|
29
|
+
h.merge Hash[versions.map { |name, version| [name, { :url => version.url }] }]
|
|
29
30
|
end
|
|
30
31
|
|
|
31
32
|
end # Url
|
|
@@ -114,9 +114,15 @@ module CarrierWave
|
|
|
114
114
|
# versions if their parameters somehow have changed.
|
|
115
115
|
#
|
|
116
116
|
def recreate_versions!
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
# Some files could possibly not be stored on the local disk. This
|
|
118
|
+
# doesn't play nicely with processing. Make sure that we're only
|
|
119
|
+
# processing a cached file
|
|
120
|
+
#
|
|
121
|
+
# The call to store! will trigger the necessary callbacks to both
|
|
122
|
+
# process this version and all sub-versions
|
|
123
|
+
cache_stored_file! if !cached?
|
|
124
|
+
|
|
125
|
+
store!
|
|
120
126
|
end
|
|
121
127
|
|
|
122
128
|
private
|
|
@@ -130,9 +136,15 @@ module CarrierWave
|
|
|
130
136
|
end
|
|
131
137
|
|
|
132
138
|
def cache_versions!(new_file)
|
|
139
|
+
# We might have processed the new_file argument after the callbacks were
|
|
140
|
+
# initialized, so get the actual file based off of the current state of
|
|
141
|
+
# our file
|
|
142
|
+
processed_parent = SanitizedFile.new :tempfile => self.file,
|
|
143
|
+
:filename => new_file.original_filename
|
|
144
|
+
|
|
133
145
|
versions.each do |name, v|
|
|
134
146
|
v.send(:cache_id=, cache_id)
|
|
135
|
-
v.cache!(
|
|
147
|
+
v.cache!(processed_parent)
|
|
136
148
|
end
|
|
137
149
|
end
|
|
138
150
|
|
data/lib/carrierwave/version.rb
CHANGED
data/lib/carrierwave.rb
CHANGED
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
require 'fileutils'
|
|
4
4
|
require 'active_support/core_ext/object/blank'
|
|
5
|
-
require 'active_support/core_ext/class/
|
|
5
|
+
require 'active_support/core_ext/class/attribute'
|
|
6
6
|
require 'active_support/concern'
|
|
7
|
+
require 'active_support/memoizable'
|
|
7
8
|
|
|
8
9
|
module CarrierWave
|
|
9
10
|
|
|
@@ -35,6 +36,7 @@ module CarrierWave
|
|
|
35
36
|
module Storage
|
|
36
37
|
autoload :Abstract, 'carrierwave/storage/abstract'
|
|
37
38
|
autoload :File, 'carrierwave/storage/file'
|
|
39
|
+
autoload :Fog, 'carrierwave/storage/fog'
|
|
38
40
|
autoload :S3, 'carrierwave/storage/s3'
|
|
39
41
|
autoload :GridFS, 'carrierwave/storage/grid_fs'
|
|
40
42
|
autoload :RightS3, 'carrierwave/storage/right_s3'
|
|
@@ -84,6 +86,12 @@ elsif defined?(Rails)
|
|
|
84
86
|
initializer "carrierwave.setup_paths" do
|
|
85
87
|
CarrierWave.root = Rails.root.join(Rails.public_path).to_s
|
|
86
88
|
end
|
|
89
|
+
|
|
90
|
+
initializer "carrierwave.active_record" do
|
|
91
|
+
ActiveSupport.on_load :active_record do
|
|
92
|
+
require 'carrierwave/orm/activerecord'
|
|
93
|
+
end
|
|
94
|
+
end
|
|
87
95
|
end
|
|
88
96
|
end
|
|
89
97
|
|
|
@@ -93,8 +101,6 @@ elsif defined?(Sinatra)
|
|
|
93
101
|
|
|
94
102
|
end
|
|
95
103
|
|
|
96
|
-
|
|
97
|
-
require 'carrierwave/orm/activerecord' if defined?(ActiveRecord)
|
|
98
104
|
require 'carrierwave/orm/datamapper' if defined?(DataMapper)
|
|
99
105
|
require 'carrierwave/orm/sequel' if defined?(Sequel)
|
|
100
106
|
require 'carrierwave/orm/mongoid' if defined?(Mongoid)
|
|
@@ -8,7 +8,7 @@ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
|
|
|
8
8
|
|
|
9
9
|
# Choose what kind of storage to use for this uploader:
|
|
10
10
|
storage :file
|
|
11
|
-
# storage :
|
|
11
|
+
# storage :fog
|
|
12
12
|
|
|
13
13
|
# Override the directory where uploaded files will be stored.
|
|
14
14
|
# This is a sensible default for uploaders that are meant to be mounted:
|
|
@@ -40,6 +40,7 @@ class <%= class_name %>Uploader < CarrierWave::Uploader::Base
|
|
|
40
40
|
# end
|
|
41
41
|
|
|
42
42
|
# Override the filename of the uploaded files:
|
|
43
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
|
43
44
|
# def filename
|
|
44
45
|
# "something.jpg" if original_filename
|
|
45
46
|
# end
|