s3 0.3.8 → 0.3.9
Sign up to get free protection for your applications and to get access to all the features.
- data/extra/s3_paperclip.rb +20 -4
- data/lib/s3/connection.rb +4 -1
- data/lib/s3/parser.rb +2 -2
- data/lib/s3/version.rb +1 -1
- metadata +47 -59
data/extra/s3_paperclip.rb
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
#
|
6
6
|
# has_attached_file :image,
|
7
7
|
# :s3_host_alias => "bucket.domain.tld",
|
8
|
+
# :s3_headers => { :cache_control => 10.years.from_now.httpdate },
|
8
9
|
# :url => ":s3_alias_url",
|
9
10
|
# :styles => {
|
10
11
|
# :medium => "300x300>",
|
@@ -47,13 +48,13 @@ module Paperclip
|
|
47
48
|
@bucket = @service.buckets.build(@bucket_name)
|
48
49
|
end
|
49
50
|
Paperclip.interpolates(:s3_alias_url) do |attachment, style|
|
50
|
-
"#{attachment.s3_protocol}://#{attachment.s3_host_alias}/#{attachment.path(style).gsub(%r{^/}, "")}"
|
51
|
+
"#{attachment.s3_protocol}://#{attachment.s3_host_alias}/#{Paperclip::Storage::S3.encode_path(attachment.path(style)).gsub(%r{^/}, "")}"
|
51
52
|
end
|
52
53
|
Paperclip.interpolates(:s3_path_url) do |attachment, style|
|
53
|
-
"#{attachment.s3_protocol}://s3.amazonaws.com/#{attachment.bucket_name}/#{attachment.path(style).gsub(%r{^/}, "")}"
|
54
|
+
"#{attachment.s3_protocol}://s3.amazonaws.com/#{attachment.bucket_name}/#{Paperclip::Storage::S3.encode_path(attachment.path(style)).gsub(%r{^/}, "")}"
|
54
55
|
end
|
55
56
|
Paperclip.interpolates(:s3_domain_url) do |attachment, style|
|
56
|
-
"#{attachment.s3_protocol}://#{attachment.bucket_name}.s3.amazonaws.com/#{attachment.path(style).gsub(%r{^/}, "")}"
|
57
|
+
"#{attachment.s3_protocol}://#{attachment.bucket_name}.s3.amazonaws.com/#{Paperclip::Storage::S3.encode_path(attachment.path(style)).gsub(%r{^/}, "")}"
|
57
58
|
end
|
58
59
|
end
|
59
60
|
|
@@ -73,6 +74,11 @@ module Paperclip
|
|
73
74
|
@s3_host_alias
|
74
75
|
end
|
75
76
|
|
77
|
+
def content_disposition(style = default_style)
|
78
|
+
cd = @s3_headers[:content_disposition]
|
79
|
+
cd.respond_to?(:call) ? cd.call(self, style) : cd
|
80
|
+
end
|
81
|
+
|
76
82
|
def parse_credentials creds
|
77
83
|
creds = find_credentials(creds).stringify_keys
|
78
84
|
(creds[RAILS_ENV] || creds).symbolize_keys
|
@@ -109,6 +115,15 @@ module Paperclip
|
|
109
115
|
file
|
110
116
|
end
|
111
117
|
|
118
|
+
# Encodes all characters except forward-slash (/) and explicitly legal URL characters
|
119
|
+
def self.encode_path(path)
|
120
|
+
URI.encode(path, /[^#{URI::REGEXP::PATTERN::UNRESERVED}\/]/)
|
121
|
+
end
|
122
|
+
|
123
|
+
def encoded_path(style)
|
124
|
+
Paperclip::Storage::S3.encode_path(path(style))
|
125
|
+
end
|
126
|
+
|
112
127
|
def flush_writes #:nodoc:
|
113
128
|
@queued_for_write.each do |style, file|
|
114
129
|
begin
|
@@ -119,7 +134,8 @@ module Paperclip
|
|
119
134
|
object.acl = @s3_permissions
|
120
135
|
object.storage_class = @s3_storage_class
|
121
136
|
object.content_type = instance_read(:content_type)
|
122
|
-
object.
|
137
|
+
object.cache_control = @s3_headers[:cache_control]
|
138
|
+
object.content_disposition = content_disposition(style)
|
123
139
|
object.content_encoding = @s3_headers[:content_encoding]
|
124
140
|
object.save
|
125
141
|
rescue ::S3::Error::ResponseError => e
|
data/lib/s3/connection.rb
CHANGED
@@ -61,12 +61,15 @@ module S3
|
|
61
61
|
params = options.fetch(:params, {})
|
62
62
|
headers = options.fetch(:headers, {})
|
63
63
|
|
64
|
+
# Must be done before adding params
|
65
|
+
# Encodes all characters except forward-slash (/) and explicitly legal URL characters
|
66
|
+
path = URI.escape(path, /[^#{URI::REGEXP::PATTERN::UNRESERVED}\/]/)
|
67
|
+
|
64
68
|
if params
|
65
69
|
params = params.is_a?(String) ? params : self.class.parse_params(params)
|
66
70
|
path << "?#{params}"
|
67
71
|
end
|
68
72
|
|
69
|
-
path = URI.escape(path)
|
70
73
|
request = Request.new(@chunk_size, method.to_s.upcase, !!body, method.to_s.upcase != "HEAD", path)
|
71
74
|
|
72
75
|
headers = self.class.parse_headers(headers)
|
data/lib/s3/parser.rb
CHANGED
@@ -3,7 +3,7 @@ module S3
|
|
3
3
|
include REXML
|
4
4
|
|
5
5
|
def rexml_document(xml)
|
6
|
-
xml.force_encoding(Encoding::UTF_8) if xml.respond_to? :force_encoding
|
6
|
+
xml.force_encoding(::Encoding::UTF_8) if xml.respond_to? :force_encoding
|
7
7
|
Document.new(xml)
|
8
8
|
end
|
9
9
|
|
@@ -44,7 +44,7 @@ module S3
|
|
44
44
|
message = document.elements["Error/Message"].text
|
45
45
|
[code, message]
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
def parse_is_truncated xml
|
49
49
|
rexml_document(xml).elements["ListBucketResult/IsTruncated"].text =='true'
|
50
50
|
end
|
data/lib/s3/version.rb
CHANGED
metadata
CHANGED
@@ -1,72 +1,68 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: s3
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.9
|
4
5
|
prerelease:
|
5
|
-
version: 0.3.8
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
-
|
7
|
+
authors:
|
8
|
+
- Jakub Kuźma
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
dependencies:
|
16
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2011-11-05 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
17
15
|
name: proxies
|
18
|
-
requirement: &
|
16
|
+
requirement: &11258640 !ruby/object:Gem::Requirement
|
19
17
|
none: false
|
20
|
-
requirements:
|
18
|
+
requirements:
|
21
19
|
- - ~>
|
22
|
-
- !ruby/object:Gem::Version
|
20
|
+
- !ruby/object:Gem::Version
|
23
21
|
version: 0.2.0
|
24
22
|
type: :runtime
|
25
23
|
prerelease: false
|
26
|
-
version_requirements: *
|
27
|
-
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: *11258640
|
25
|
+
- !ruby/object:Gem::Dependency
|
28
26
|
name: test-unit
|
29
|
-
requirement: &
|
27
|
+
requirement: &11258020 !ruby/object:Gem::Requirement
|
30
28
|
none: false
|
31
|
-
requirements:
|
32
|
-
- -
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
35
33
|
type: :development
|
36
34
|
prerelease: false
|
37
|
-
version_requirements: *
|
38
|
-
- !ruby/object:Gem::Dependency
|
35
|
+
version_requirements: *11258020
|
36
|
+
- !ruby/object:Gem::Dependency
|
39
37
|
name: mocha
|
40
|
-
requirement: &
|
38
|
+
requirement: &11257380 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version:
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
46
44
|
type: :development
|
47
45
|
prerelease: false
|
48
|
-
version_requirements: *
|
49
|
-
- !ruby/object:Gem::Dependency
|
46
|
+
version_requirements: *11257380
|
47
|
+
- !ruby/object:Gem::Dependency
|
50
48
|
name: bundler
|
51
|
-
requirement: &
|
49
|
+
requirement: &11256840 !ruby/object:Gem::Requirement
|
52
50
|
none: false
|
53
|
-
requirements:
|
54
|
-
- -
|
55
|
-
- !ruby/object:Gem::Version
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
56
54
|
version: 1.0.0
|
57
55
|
type: :development
|
58
56
|
prerelease: false
|
59
|
-
version_requirements: *
|
60
|
-
description:
|
61
|
-
|
57
|
+
version_requirements: *11256840
|
58
|
+
description: ! 'S3 library provides access to Amazon''s Simple Storage Service. It
|
59
|
+
supports both: European and US buckets through REST API.'
|
60
|
+
email:
|
62
61
|
- qoobaa@gmail.com
|
63
62
|
executables: []
|
64
|
-
|
65
63
|
extensions: []
|
66
|
-
|
67
64
|
extra_rdoc_files: []
|
68
|
-
|
69
|
-
files:
|
65
|
+
files:
|
70
66
|
- .gitignore
|
71
67
|
- Gemfile
|
72
68
|
- Gemfile.lock
|
@@ -94,36 +90,28 @@ files:
|
|
94
90
|
- test/service_test.rb
|
95
91
|
- test/signature_test.rb
|
96
92
|
- test/test_helper.rb
|
97
|
-
has_rdoc: true
|
98
93
|
homepage: http://jah.pl/projects/s3.html
|
99
94
|
licenses: []
|
100
|
-
|
101
95
|
post_install_message:
|
102
96
|
rdoc_options: []
|
103
|
-
|
104
|
-
require_paths:
|
97
|
+
require_paths:
|
105
98
|
- lib
|
106
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
100
|
none: false
|
108
|
-
requirements:
|
109
|
-
- -
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
|
112
|
-
|
113
|
-
- 0
|
114
|
-
version: "0"
|
115
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ! '>='
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
106
|
none: false
|
117
|
-
requirements:
|
118
|
-
- -
|
119
|
-
- !ruby/object:Gem::Version
|
107
|
+
requirements:
|
108
|
+
- - ! '>='
|
109
|
+
- !ruby/object:Gem::Version
|
120
110
|
version: 1.3.6
|
121
111
|
requirements: []
|
122
|
-
|
123
112
|
rubyforge_project: s3
|
124
|
-
rubygems_version: 1.
|
113
|
+
rubygems_version: 1.8.10
|
125
114
|
signing_key:
|
126
115
|
specification_version: 3
|
127
116
|
summary: Library for accessing S3 objects and buckets
|
128
117
|
test_files: []
|
129
|
-
|