paperclip 5.0.0.beta2 → 5.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +17 -0
- data/.hound.yml +5 -16
- data/.travis.yml +14 -15
- data/Appraisals +3 -23
- data/CONTRIBUTING.md +10 -4
- data/Gemfile +1 -0
- data/NEWS +78 -2
- data/README.md +175 -81
- data/Rakefile +1 -1
- data/UPGRADING +1 -1
- data/features/basic_integration.feature +2 -2
- data/features/step_definitions/attachment_steps.rb +6 -6
- data/features/step_definitions/rails_steps.rb +29 -22
- data/features/step_definitions/s3_steps.rb +1 -1
- data/features/support/env.rb +1 -0
- data/features/support/paths.rb +1 -1
- data/features/support/rails.rb +0 -24
- data/gemfiles/{4.2.awsv2.0.gemfile → 4.2.gemfile} +1 -1
- data/gemfiles/{5.0.awsv2.1.gemfile → 5.0.gemfile} +2 -2
- data/lib/generators/paperclip/paperclip_generator.rb +9 -1
- data/lib/generators/paperclip/templates/paperclip_migration.rb.erb +1 -1
- data/lib/paperclip.rb +13 -10
- data/lib/paperclip/attachment.rb +16 -6
- data/lib/paperclip/content_type_detector.rb +3 -2
- data/lib/paperclip/errors.rb +3 -1
- data/lib/paperclip/file_command_content_type_detector.rb +1 -1
- data/lib/paperclip/geometry_detector_factory.rb +2 -2
- data/lib/paperclip/helpers.rb +15 -12
- data/lib/paperclip/interpolations.rb +1 -1
- data/lib/paperclip/io_adapters/abstract_adapter.rb +29 -3
- data/lib/paperclip/io_adapters/attachment_adapter.rb +10 -5
- data/lib/paperclip/io_adapters/data_uri_adapter.rb +8 -8
- data/lib/paperclip/io_adapters/empty_string_adapter.rb +5 -4
- data/lib/paperclip/io_adapters/file_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/http_url_proxy_adapter.rb +7 -7
- data/lib/paperclip/io_adapters/identity_adapter.rb +12 -6
- data/lib/paperclip/io_adapters/nil_adapter.rb +8 -5
- data/lib/paperclip/io_adapters/registry.rb +6 -2
- data/lib/paperclip/io_adapters/stringio_adapter.rb +9 -6
- data/lib/paperclip/io_adapters/uploaded_file_adapter.rb +10 -6
- data/lib/paperclip/io_adapters/uri_adapter.rb +41 -19
- data/lib/paperclip/matchers/validate_attachment_content_type_matcher.rb +4 -4
- data/lib/paperclip/media_type_spoof_detector.rb +3 -2
- data/lib/paperclip/processor.rb +5 -4
- data/lib/paperclip/storage/filesystem.rb +13 -2
- data/lib/paperclip/storage/fog.rb +12 -7
- data/lib/paperclip/storage/s3.rb +46 -19
- data/lib/paperclip/thumbnail.rb +18 -8
- data/lib/paperclip/url_generator.rb +17 -13
- data/lib/paperclip/validators.rb +1 -1
- data/lib/paperclip/version.rb +3 -1
- data/lib/tasks/paperclip.rake +18 -4
- data/paperclip.gemspec +4 -5
- data/spec/paperclip/attachment_processing_spec.rb +2 -4
- data/spec/paperclip/attachment_spec.rb +40 -9
- data/spec/paperclip/content_type_detector_spec.rb +1 -1
- data/spec/paperclip/file_command_content_type_detector_spec.rb +15 -1
- data/spec/paperclip/io_adapters/abstract_adapter_spec.rb +76 -22
- data/spec/paperclip/io_adapters/attachment_adapter_spec.rb +6 -3
- data/spec/paperclip/io_adapters/data_uri_adapter_spec.rb +7 -1
- data/spec/paperclip/io_adapters/file_adapter_spec.rb +2 -2
- data/spec/paperclip/io_adapters/http_url_proxy_adapter_spec.rb +26 -6
- data/spec/paperclip/io_adapters/identity_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/registry_spec.rb +2 -2
- data/spec/paperclip/io_adapters/stringio_adapter_spec.rb +1 -1
- data/spec/paperclip/io_adapters/uploaded_file_adapter_spec.rb +5 -5
- data/spec/paperclip/io_adapters/uri_adapter_spec.rb +77 -7
- data/spec/paperclip/matchers/validate_attachment_content_type_matcher_spec.rb +10 -0
- data/spec/paperclip/media_type_spoof_detector_spec.rb +27 -3
- data/spec/paperclip/paperclip_spec.rb +13 -13
- data/spec/paperclip/processor_spec.rb +4 -4
- data/spec/paperclip/storage/fog_spec.rb +28 -0
- data/spec/paperclip/storage/s3_live_spec.rb +12 -10
- data/spec/paperclip/storage/s3_spec.rb +150 -39
- data/spec/paperclip/tempfile_spec.rb +35 -0
- data/spec/paperclip/thumbnail_spec.rb +38 -35
- data/spec/paperclip/url_generator_spec.rb +54 -43
- data/spec/paperclip/validators_spec.rb +3 -2
- data/spec/spec_helper.rb +3 -1
- data/spec/support/assertions.rb +5 -1
- data/spec/support/conditional_filter_helper.rb +5 -0
- data/spec/support/mock_attachment.rb +2 -0
- data/spec/support/mock_url_generator_builder.rb +2 -2
- metadata +37 -36
- data/gemfiles/4.2.awsv2.1.gemfile +0 -17
- data/gemfiles/4.2.awsv2.gemfile +0 -20
- data/gemfiles/5.0.awsv2.0.gemfile +0 -17
- data/gemfiles/5.0.awsv2.gemfile +0 -25
data/lib/paperclip/errors.rb
CHANGED
@@ -19,7 +19,9 @@ module Paperclip
|
|
19
19
|
end
|
20
20
|
|
21
21
|
# Will be thrown when ImageMagic cannot determine the uploaded file's
|
22
|
-
# metadata, usually this would mean the file is not an image.
|
22
|
+
# metadata, usually this would mean the file is not an image. If you are
|
23
|
+
# consistently receiving this error on PDFs make sure that you have
|
24
|
+
# installed Ghostscript.
|
23
25
|
class NotIdentifiedByImageMagickError < Paperclip::Error
|
24
26
|
end
|
25
27
|
|
@@ -16,7 +16,7 @@ module Paperclip
|
|
16
16
|
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
|
17
17
|
type = begin
|
18
18
|
Paperclip.run("file", "-b --mime :file", file: @filename)
|
19
|
-
rescue
|
19
|
+
rescue Terrapin::CommandLineError => e
|
20
20
|
Paperclip.log("Error while determining content type: #{e}")
|
21
21
|
SENSIBLE_DEFAULT
|
22
22
|
end
|
@@ -24,9 +24,9 @@ module Paperclip
|
|
24
24
|
:swallow_stderr => true
|
25
25
|
}
|
26
26
|
)
|
27
|
-
rescue
|
27
|
+
rescue Terrapin::ExitStatusError
|
28
28
|
""
|
29
|
-
rescue
|
29
|
+
rescue Terrapin::CommandNotFoundError => e
|
30
30
|
raise_because_imagemagick_missing
|
31
31
|
end
|
32
32
|
end
|
data/lib/paperclip/helpers.rb
CHANGED
@@ -8,28 +8,31 @@ module Paperclip
|
|
8
8
|
Paperclip::Interpolations[key] = block
|
9
9
|
end
|
10
10
|
|
11
|
-
# The run method takes the name of a binary to run, the arguments
|
12
|
-
# and some options
|
11
|
+
# The run method takes the name of a binary to run, the arguments
|
12
|
+
# to that binary, the values to interpolate and some local options.
|
13
13
|
#
|
14
|
-
#
|
15
|
-
# on the filesystem. Colon-separated, just like $PATH.
|
14
|
+
# :cmd -> The name of a binary to run.
|
16
15
|
#
|
17
|
-
#
|
18
|
-
# of the binary. Defaults to [0].
|
16
|
+
# :arguments -> The command line arguments to that binary.
|
19
17
|
#
|
20
|
-
#
|
21
|
-
# This will only log if logging in general is set to true as well.
|
18
|
+
# :interpolation_values -> Values to be interpolated into the arguments.
|
22
19
|
#
|
23
|
-
#
|
20
|
+
# :local_options -> The options to be used by Cocain::CommandLine.
|
21
|
+
# These could be: runner
|
22
|
+
# logger
|
23
|
+
# swallow_stderr
|
24
|
+
# expected_outcodes
|
25
|
+
# environment
|
26
|
+
# runner_options
|
24
27
|
#
|
25
28
|
def run(cmd, arguments = "", interpolation_values = {}, local_options = {})
|
26
29
|
command_path = options[:command_path]
|
27
|
-
|
28
|
-
|
30
|
+
terrapin_path_array = Terrapin::CommandLine.path.try(:split, Terrapin::OS.path_separator)
|
31
|
+
Terrapin::CommandLine.path = [terrapin_path_array, command_path].flatten.compact.uniq
|
29
32
|
if logging? && (options[:log_command] || local_options[:log_command])
|
30
33
|
local_options = local_options.merge(:logger => logger)
|
31
34
|
end
|
32
|
-
|
35
|
+
Terrapin::CommandLine.new(cmd, arguments, local_options).run(interpolation_values)
|
33
36
|
end
|
34
37
|
|
35
38
|
# Find all instances of the given Active Record model +klass+ with attachment +name+.
|
@@ -141,7 +141,7 @@ module Paperclip
|
|
141
141
|
# It's possible, though unlikely, that the mime type is not in the
|
142
142
|
# database, so just use the part after the '/' in the mime type as the
|
143
143
|
# extension.
|
144
|
-
%r{/([^/]*)\
|
144
|
+
%r{/([^/]*)\z}.match(attachment.content_type)[1]
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
@@ -5,11 +5,23 @@ module Paperclip
|
|
5
5
|
OS_RESTRICTED_CHARACTERS = %r{[/:]}
|
6
6
|
|
7
7
|
attr_reader :content_type, :original_filename, :size
|
8
|
-
delegate :binmode, :binmode?, :close, :close!, :closed?, :eof?, :path, :rewind, :unlink, :to => :@tempfile
|
8
|
+
delegate :binmode, :binmode?, :close, :close!, :closed?, :eof?, :path, :readbyte, :rewind, :unlink, :to => :@tempfile
|
9
9
|
alias :length :size
|
10
10
|
|
11
|
+
def initialize(target, options = {})
|
12
|
+
@target = target
|
13
|
+
@options = options
|
14
|
+
end
|
15
|
+
|
11
16
|
def fingerprint
|
12
|
-
@fingerprint ||=
|
17
|
+
@fingerprint ||= begin
|
18
|
+
digest = @options.fetch(:hash_digest).new
|
19
|
+
File.open(path, "rb") do |f|
|
20
|
+
buf = ""
|
21
|
+
digest.update(buf) while f.read(16384, buf)
|
22
|
+
end
|
23
|
+
digest.hexdigest
|
24
|
+
end
|
13
25
|
end
|
14
26
|
|
15
27
|
def read(length = nil, buffer = nil)
|
@@ -40,8 +52,22 @@ module Paperclip
|
|
40
52
|
end
|
41
53
|
|
42
54
|
def copy_to_tempfile(src)
|
43
|
-
|
55
|
+
link_or_copy_file(src.path, destination.path)
|
44
56
|
destination
|
45
57
|
end
|
58
|
+
|
59
|
+
def link_or_copy_file(src, dest)
|
60
|
+
Paperclip.log("Trying to link #{src} to #{dest}")
|
61
|
+
FileUtils.ln(src, dest, force: true) # overwrite existing
|
62
|
+
@destination.close
|
63
|
+
@destination.open.binmode
|
64
|
+
rescue Errno::EXDEV, Errno::EPERM, Errno::ENOENT, Errno::EEXIST => e
|
65
|
+
Paperclip.log(
|
66
|
+
"Link failed with #{e.message}; copying link #{src} to #{dest}"
|
67
|
+
)
|
68
|
+
FileUtils.cp(src, dest)
|
69
|
+
@destination.close
|
70
|
+
@destination.open.binmode
|
71
|
+
end
|
46
72
|
end
|
47
73
|
end
|
@@ -1,6 +1,13 @@
|
|
1
1
|
module Paperclip
|
2
2
|
class AttachmentAdapter < AbstractAdapter
|
3
|
-
def
|
3
|
+
def self.register
|
4
|
+
Paperclip.io_adapters.register self do |target|
|
5
|
+
Paperclip::Attachment === target || Paperclip::Style === target
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(target, options = {})
|
10
|
+
super
|
4
11
|
@target, @style = case target
|
5
12
|
when Paperclip::Attachment
|
6
13
|
[target, :original]
|
@@ -22,7 +29,7 @@ module Paperclip
|
|
22
29
|
|
23
30
|
def copy_to_tempfile(source)
|
24
31
|
if source.staged?
|
25
|
-
|
32
|
+
link_or_copy_file(source.staged_path(@style), destination.path)
|
26
33
|
else
|
27
34
|
source.copy_to_local_file(@style, destination.path)
|
28
35
|
end
|
@@ -31,6 +38,4 @@ module Paperclip
|
|
31
38
|
end
|
32
39
|
end
|
33
40
|
|
34
|
-
Paperclip.
|
35
|
-
Paperclip::Attachment === target || Paperclip::Style === target
|
36
|
-
end
|
41
|
+
Paperclip::AttachmentAdapter.register
|
@@ -1,22 +1,22 @@
|
|
1
1
|
module Paperclip
|
2
2
|
class DataUriAdapter < StringioAdapter
|
3
|
+
def self.register
|
4
|
+
Paperclip.io_adapters.register self do |target|
|
5
|
+
String === target && target =~ REGEXP
|
6
|
+
end
|
7
|
+
end
|
3
8
|
|
4
9
|
REGEXP = /\Adata:([-\w]+\/[-\w\+\.]+)?;base64,(.*)/m
|
5
10
|
|
6
|
-
def initialize(target_uri)
|
7
|
-
super(extract_target(target_uri))
|
11
|
+
def initialize(target_uri, options = {})
|
12
|
+
super(extract_target(target_uri), options)
|
8
13
|
end
|
9
14
|
|
10
15
|
private
|
11
16
|
|
12
17
|
def extract_target(uri)
|
13
18
|
data_uri_parts = uri.match(REGEXP) || []
|
14
|
-
StringIO.new(Base64.decode64(data_uri_parts[2] ||
|
19
|
+
StringIO.new(Base64.decode64(data_uri_parts[2] || ""))
|
15
20
|
end
|
16
|
-
|
17
21
|
end
|
18
22
|
end
|
19
|
-
|
20
|
-
Paperclip.io_adapters.register Paperclip::DataUriAdapter do |target|
|
21
|
-
String === target && target =~ Paperclip::DataUriAdapter::REGEXP
|
22
|
-
end
|
@@ -1,6 +1,9 @@
|
|
1
1
|
module Paperclip
|
2
2
|
class EmptyStringAdapter < AbstractAdapter
|
3
|
-
def
|
3
|
+
def self.register
|
4
|
+
Paperclip.io_adapters.register self do |target|
|
5
|
+
target.is_a?(String) && target.empty?
|
6
|
+
end
|
4
7
|
end
|
5
8
|
|
6
9
|
def nil?
|
@@ -13,6 +16,4 @@ module Paperclip
|
|
13
16
|
end
|
14
17
|
end
|
15
18
|
|
16
|
-
Paperclip.
|
17
|
-
target.is_a?(String) && target.empty?
|
18
|
-
end
|
19
|
+
Paperclip::EmptyStringAdapter.register
|
@@ -1,14 +1,22 @@
|
|
1
1
|
module Paperclip
|
2
2
|
class FileAdapter < AbstractAdapter
|
3
|
-
def
|
4
|
-
|
3
|
+
def self.register
|
4
|
+
Paperclip.io_adapters.register self do |target|
|
5
|
+
File === target || ::Tempfile === target
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(target, options = {})
|
10
|
+
super
|
5
11
|
cache_current_values
|
6
12
|
end
|
7
13
|
|
8
14
|
private
|
9
15
|
|
10
16
|
def cache_current_values
|
11
|
-
|
17
|
+
if @target.respond_to?(:original_filename)
|
18
|
+
self.original_filename = @target.original_filename
|
19
|
+
end
|
12
20
|
self.original_filename ||= File.basename(@target.path)
|
13
21
|
@tempfile = copy_to_tempfile(@target)
|
14
22
|
@content_type = ContentTypeDetector.new(@target.path).detect
|
@@ -17,6 +25,4 @@ module Paperclip
|
|
17
25
|
end
|
18
26
|
end
|
19
27
|
|
20
|
-
Paperclip.
|
21
|
-
File === target || Tempfile === target
|
22
|
-
end
|
28
|
+
Paperclip::FileAdapter.register
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module Paperclip
|
2
2
|
class HttpUrlProxyAdapter < UriAdapter
|
3
|
+
def self.register
|
4
|
+
Paperclip.io_adapters.register self do |target|
|
5
|
+
String === target && target =~ REGEXP
|
6
|
+
end
|
7
|
+
end
|
3
8
|
|
4
9
|
REGEXP = /\Ahttps?:\/\//
|
5
10
|
|
6
|
-
def initialize(target)
|
7
|
-
super(URI(target))
|
11
|
+
def initialize(target, options = {})
|
12
|
+
super(URI(URI.escape(target)), options)
|
8
13
|
end
|
9
|
-
|
10
14
|
end
|
11
15
|
end
|
12
|
-
|
13
|
-
Paperclip.io_adapters.register Paperclip::HttpUrlProxyAdapter do |target|
|
14
|
-
String === target && target =~ Paperclip::HttpUrlProxyAdapter::REGEXP
|
15
|
-
end
|
@@ -1,12 +1,18 @@
|
|
1
1
|
module Paperclip
|
2
2
|
class IdentityAdapter < AbstractAdapter
|
3
|
-
def
|
4
|
-
|
3
|
+
def self.register
|
4
|
+
Paperclip.io_adapters.register Paperclip::IdentityAdapter.new do |target|
|
5
|
+
Paperclip.io_adapters.registered?(target)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize
|
5
10
|
end
|
6
|
-
end
|
7
|
-
end
|
8
11
|
|
9
|
-
|
10
|
-
|
12
|
+
def new(target, _)
|
13
|
+
target
|
14
|
+
end
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
18
|
+
Paperclip::IdentityAdapter.register
|
@@ -1,8 +1,13 @@
|
|
1
1
|
module Paperclip
|
2
2
|
class NilAdapter < AbstractAdapter
|
3
|
-
def
|
3
|
+
def self.register
|
4
|
+
Paperclip.io_adapters.register self do |target|
|
5
|
+
target.nil? || ((Paperclip::Attachment === target) && !target.present?)
|
6
|
+
end
|
4
7
|
end
|
5
8
|
|
9
|
+
def initialize(_target, _options = {}); end
|
10
|
+
|
6
11
|
def original_filename
|
7
12
|
""
|
8
13
|
end
|
@@ -19,7 +24,7 @@ module Paperclip
|
|
19
24
|
true
|
20
25
|
end
|
21
26
|
|
22
|
-
def read(*
|
27
|
+
def read(*_args)
|
23
28
|
nil
|
24
29
|
end
|
25
30
|
|
@@ -29,6 +34,4 @@ module Paperclip
|
|
29
34
|
end
|
30
35
|
end
|
31
36
|
|
32
|
-
Paperclip.
|
33
|
-
target.nil? || ( (Paperclip::Attachment === target) && !target.present? )
|
34
|
-
end
|
37
|
+
Paperclip::NilAdapter.register
|
@@ -12,6 +12,10 @@ module Paperclip
|
|
12
12
|
@registered_handlers << [block, handler_class]
|
13
13
|
end
|
14
14
|
|
15
|
+
def unregister(handler_class)
|
16
|
+
@registered_handlers.reject! { |_, klass| klass == handler_class }
|
17
|
+
end
|
18
|
+
|
15
19
|
def handler_for(target)
|
16
20
|
@registered_handlers.each do |tester, handler|
|
17
21
|
return handler if tester.call(target)
|
@@ -25,8 +29,8 @@ module Paperclip
|
|
25
29
|
end
|
26
30
|
end
|
27
31
|
|
28
|
-
def for(target)
|
29
|
-
handler_for(target).new(target)
|
32
|
+
def for(target, options = {})
|
33
|
+
handler_for(target).new(target, options)
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
@@ -1,7 +1,13 @@
|
|
1
1
|
module Paperclip
|
2
2
|
class StringioAdapter < AbstractAdapter
|
3
|
-
def
|
4
|
-
|
3
|
+
def self.register
|
4
|
+
Paperclip.io_adapters.register self do |target|
|
5
|
+
StringIO === target
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(target, options = {})
|
10
|
+
super
|
5
11
|
cache_current_values
|
6
12
|
end
|
7
13
|
|
@@ -24,10 +30,7 @@ module Paperclip
|
|
24
30
|
destination.rewind
|
25
31
|
destination
|
26
32
|
end
|
27
|
-
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
31
|
-
Paperclip.
|
32
|
-
StringIO === target
|
33
|
-
end
|
36
|
+
Paperclip::StringioAdapter.register
|
@@ -1,7 +1,13 @@
|
|
1
1
|
module Paperclip
|
2
2
|
class UploadedFileAdapter < AbstractAdapter
|
3
|
-
def
|
4
|
-
|
3
|
+
def self.register
|
4
|
+
Paperclip.io_adapters.register self do |target|
|
5
|
+
target.class.name.include?("UploadedFile")
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(target, options = {})
|
10
|
+
super
|
5
11
|
cache_current_values
|
6
12
|
|
7
13
|
if @target.respond_to?(:tempfile)
|
@@ -24,7 +30,7 @@ module Paperclip
|
|
24
30
|
end
|
25
31
|
|
26
32
|
def content_type_detector
|
27
|
-
self.class.content_type_detector
|
33
|
+
self.class.content_type_detector || Paperclip::ContentTypeDetector
|
28
34
|
end
|
29
35
|
|
30
36
|
def determine_content_type
|
@@ -37,6 +43,4 @@ module Paperclip
|
|
37
43
|
end
|
38
44
|
end
|
39
45
|
|
40
|
-
Paperclip.
|
41
|
-
target.class.name.include?("UploadedFile")
|
42
|
-
end
|
46
|
+
Paperclip::UploadedFileAdapter.register
|
@@ -1,35 +1,61 @@
|
|
1
|
-
require
|
1
|
+
require "open-uri"
|
2
2
|
|
3
3
|
module Paperclip
|
4
4
|
class UriAdapter < AbstractAdapter
|
5
|
-
|
6
|
-
|
5
|
+
attr_writer :content_type
|
6
|
+
|
7
|
+
def self.register
|
8
|
+
Paperclip.io_adapters.register self do |target|
|
9
|
+
target.is_a?(URI)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(target, options = {})
|
14
|
+
super
|
7
15
|
@content = download_content
|
8
16
|
cache_current_values
|
9
17
|
@tempfile = copy_to_tempfile(@content)
|
10
18
|
end
|
11
19
|
|
12
|
-
attr_writer :content_type
|
13
|
-
|
14
20
|
private
|
15
21
|
|
16
|
-
def
|
17
|
-
|
22
|
+
def cache_current_values
|
23
|
+
self.content_type = content_type_from_content || "text/html"
|
24
|
+
|
25
|
+
self.original_filename = filename_from_content_disposition ||
|
26
|
+
filename_from_path || default_filename
|
27
|
+
@size = @content.size
|
18
28
|
end
|
19
29
|
|
20
|
-
def
|
21
|
-
|
22
|
-
|
23
|
-
|
30
|
+
def content_type_from_content
|
31
|
+
if @content.respond_to?(:content_type)
|
32
|
+
@content.content_type
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def filename_from_content_disposition
|
37
|
+
if @content.meta.key?("content-disposition")
|
38
|
+
matches = @content.meta["content-disposition"].match(/filename="([^"]*)"/)
|
39
|
+
matches[1] if matches
|
40
|
+
end
|
41
|
+
end
|
24
42
|
|
25
|
-
|
26
|
-
@
|
43
|
+
def filename_from_path
|
44
|
+
@target.path.split("/").last
|
45
|
+
end
|
27
46
|
|
28
|
-
|
47
|
+
def default_filename
|
48
|
+
"index.html"
|
49
|
+
end
|
50
|
+
|
51
|
+
def download_content
|
52
|
+
options = { read_timeout: Paperclip.options[:read_timeout] }.compact
|
53
|
+
|
54
|
+
open(@target, **options)
|
29
55
|
end
|
30
56
|
|
31
57
|
def copy_to_tempfile(src)
|
32
|
-
while data = src.read(16*1024)
|
58
|
+
while data = src.read(16 * 1024)
|
33
59
|
destination.write(data)
|
34
60
|
end
|
35
61
|
src.close
|
@@ -38,7 +64,3 @@ module Paperclip
|
|
38
64
|
end
|
39
65
|
end
|
40
66
|
end
|
41
|
-
|
42
|
-
Paperclip.io_adapters.register Paperclip::UriAdapter do |target|
|
43
|
-
target.kind_of?(URI)
|
44
|
-
end
|