carrierwave-aliyun 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Changelogs.md +5 -0
- data/lib/carrierwave/aliyun/version.rb +1 -1
- data/lib/carrierwave/storage/aliyun.rb +29 -15
- data/spec/aliyun_spec.rb +3 -3
- metadata +3 -5
- data/Gemfile.lock +0 -114
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fbbd6d9b648b70321516cf2719ed5561f0eeed67
|
4
|
+
data.tar.gz: 50993ea58483e6b9ef829b10189bfb372b9350b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f080757c46c13e1d5b9a704131c507711cc72d99fb29b011ea0bf919fefec62f1a236b924a6792da473fe9d47f7ddfa829ba59b3b11cb1150e8a93a80f9cb69
|
7
|
+
data.tar.gz: 8e5a6bc22996c840400830e544f93c912041d5efcf40071a1307320062d7f7a9db4e793dcd2a66388249552f0ff20d0904ed188bc32af398f930d9e24b3fc52d
|
data/.gitignore
CHANGED
data/Changelogs.md
CHANGED
@@ -3,6 +3,7 @@ require 'carrierwave'
|
|
3
3
|
require 'digest/hmac'
|
4
4
|
require 'digest/md5'
|
5
5
|
require "rest-client"
|
6
|
+
require 'uri'
|
6
7
|
|
7
8
|
module CarrierWave
|
8
9
|
module Storage
|
@@ -13,20 +14,23 @@ module CarrierWave
|
|
13
14
|
@aliyun_access_id = options[:aliyun_access_id]
|
14
15
|
@aliyun_access_key = options[:aliyun_access_key]
|
15
16
|
@aliyun_bucket = options[:aliyun_bucket]
|
16
|
-
|
17
|
-
@
|
17
|
+
# Host for upload
|
18
|
+
@aliyun_upload_host = "#{@aliyun_bucket}.oss.aliyuncs.com"
|
18
19
|
if options[:aliyun_internal] == true
|
19
|
-
@aliyun_upload_host = "oss-internal.aliyuncs.com"
|
20
|
+
@aliyun_upload_host = "#{@aliyun_bucket}.oss-internal.aliyuncs.com"
|
20
21
|
end
|
22
|
+
# Host for get request
|
23
|
+
@aliyun_host = options[:aliyun_host] || "#{@aliyun_bucket}.oss.aliyuncs.com"
|
21
24
|
end
|
22
25
|
|
23
26
|
def put(path, file_data, options={})
|
24
27
|
path = format_path(path)
|
28
|
+
bucket_path = get_bucket_path(path)
|
25
29
|
content_md5 = Digest::MD5.hexdigest(file_data)
|
26
30
|
content_type = options[:content_type] || "image/jpg"
|
27
31
|
date = gmtdate
|
28
32
|
url = path_to_url(path)
|
29
|
-
auth_sign = sign("PUT",
|
33
|
+
auth_sign = sign("PUT", bucket_path, content_md5, content_type,date)
|
30
34
|
headers = {
|
31
35
|
"Authorization" => auth_sign,
|
32
36
|
"Content-Type" => content_type,
|
@@ -35,20 +39,21 @@ module CarrierWave
|
|
35
39
|
"Host" => @aliyun_upload_host,
|
36
40
|
"Expect" => "100-Continue"
|
37
41
|
}
|
38
|
-
|
42
|
+
RestClient.put(URI.encode(url), file_data, headers)
|
39
43
|
return path_to_url(path, :get => true)
|
40
44
|
end
|
41
45
|
|
42
46
|
def delete(path)
|
43
47
|
path = format_path(path)
|
48
|
+
bucket_path = get_bucket_path(path)
|
44
49
|
date = gmtdate
|
45
50
|
headers = {
|
46
51
|
"Host" => @aliyun_upload_host,
|
47
52
|
"Date" => date,
|
48
|
-
"Authorization" => sign("DELETE",
|
53
|
+
"Authorization" => sign("DELETE", bucket_path, "", "" ,date)
|
49
54
|
}
|
50
55
|
url = path_to_url(path)
|
51
|
-
RestClient.delete(url, headers)
|
56
|
+
RestClient.delete(URI.encode(url), headers)
|
52
57
|
return path_to_url(path, :get => true)
|
53
58
|
end
|
54
59
|
|
@@ -59,15 +64,22 @@ module CarrierWave
|
|
59
64
|
def format_path(path)
|
60
65
|
return "" if path.blank?
|
61
66
|
path.gsub!(/^\//,"")
|
62
|
-
|
67
|
+
|
68
|
+
path
|
69
|
+
end
|
70
|
+
|
71
|
+
def get_bucket_path(path)
|
72
|
+
[@aliyun_bucket,path].join("/")
|
63
73
|
end
|
64
74
|
|
65
75
|
def path_to_url(path, opts = {})
|
66
|
-
|
67
|
-
|
68
|
-
|
76
|
+
if opts[:get]
|
77
|
+
"http://#{@aliyun_host}/#{path}"
|
78
|
+
else
|
79
|
+
"http://#{@aliyun_upload_host}/#{path}"
|
80
|
+
end
|
69
81
|
end
|
70
|
-
|
82
|
+
|
71
83
|
private
|
72
84
|
def sign(verb, path, content_md5 = '', content_type = '', date)
|
73
85
|
canonicalized_oss_headers = ''
|
@@ -125,7 +137,7 @@ module CarrierWave
|
|
125
137
|
end
|
126
138
|
|
127
139
|
def url
|
128
|
-
|
140
|
+
oss_connection.path_to_url(@path, :get => true)
|
129
141
|
end
|
130
142
|
|
131
143
|
def store(data, opts = {})
|
@@ -144,11 +156,13 @@ module CarrierWave
|
|
144
156
|
|
145
157
|
def oss_connection
|
146
158
|
return @oss_connection if @oss_connection
|
147
|
-
|
159
|
+
|
148
160
|
config = {
|
149
161
|
:aliyun_access_id => @uploader.aliyun_access_id,
|
150
162
|
:aliyun_access_key => @uploader.aliyun_access_key,
|
151
|
-
:aliyun_bucket => @uploader.aliyun_bucket
|
163
|
+
:aliyun_bucket => @uploader.aliyun_bucket,
|
164
|
+
:aliyun_internal => @uploader.aliyun_internal,
|
165
|
+
:aliyun_host => @uploader.aliyun_host
|
152
166
|
}
|
153
167
|
@oss_connection ||= CarrierWave::Storage::Aliyun::Connection.new(config)
|
154
168
|
end
|
data/spec/aliyun_spec.rb
CHANGED
@@ -29,13 +29,13 @@ describe "Aliyun" do
|
|
29
29
|
|
30
30
|
it "should use default domain" do
|
31
31
|
url = @connection.put("a/a.jpg",load_file("foo.jpg").read)
|
32
|
-
url.should == "http
|
32
|
+
url.should == "http://#{ALIYUN_BUCKET}.oss.aliyuncs.com/a/a.jpg"
|
33
33
|
end
|
34
34
|
|
35
35
|
it "should support custom domain" do
|
36
36
|
@opts[:aliyun_host] = "foo.bar.com"
|
37
37
|
@connection = CarrierWave::Storage::Aliyun::Connection.new(@opts)
|
38
38
|
url = @connection.put("a/a.jpg",load_file("foo.jpg").read)
|
39
|
-
url.should == "http://foo.bar.com
|
39
|
+
url.should == "http://foo.bar.com/a/a.jpg"
|
40
40
|
end
|
41
|
-
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-aliyun
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
@@ -49,7 +49,6 @@ files:
|
|
49
49
|
- .rspec
|
50
50
|
- Changelogs.md
|
51
51
|
- Gemfile
|
52
|
-
- Gemfile.lock
|
53
52
|
- README.md
|
54
53
|
- carrierwave-aliyun.gemspec
|
55
54
|
- lib/carrierwave-aliyun.rb
|
@@ -81,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
80
|
version: '0'
|
82
81
|
requirements: []
|
83
82
|
rubyforge_project:
|
84
|
-
rubygems_version: 2.0.
|
83
|
+
rubygems_version: 2.0.3
|
85
84
|
signing_key:
|
86
85
|
specification_version: 4
|
87
86
|
summary: Aliyun OSS support for Carrierwave
|
@@ -92,4 +91,3 @@ test_files:
|
|
92
91
|
- spec/foo.zip
|
93
92
|
- spec/spec_helper.rb
|
94
93
|
- spec/upload_spec.rb
|
95
|
-
has_rdoc:
|
data/Gemfile.lock
DELETED
@@ -1,114 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://ruby.taobao.org/
|
3
|
-
specs:
|
4
|
-
actionmailer (3.2.1)
|
5
|
-
actionpack (= 3.2.1)
|
6
|
-
mail (~> 2.4.0)
|
7
|
-
actionpack (3.2.1)
|
8
|
-
activemodel (= 3.2.1)
|
9
|
-
activesupport (= 3.2.1)
|
10
|
-
builder (~> 3.0.0)
|
11
|
-
erubis (~> 2.7.0)
|
12
|
-
journey (~> 1.0.1)
|
13
|
-
rack (~> 1.4.0)
|
14
|
-
rack-cache (~> 1.1)
|
15
|
-
rack-test (~> 0.6.1)
|
16
|
-
sprockets (~> 2.1.2)
|
17
|
-
activemodel (3.2.1)
|
18
|
-
activesupport (= 3.2.1)
|
19
|
-
builder (~> 3.0.0)
|
20
|
-
activerecord (3.2.1)
|
21
|
-
activemodel (= 3.2.1)
|
22
|
-
activesupport (= 3.2.1)
|
23
|
-
arel (~> 3.0.0)
|
24
|
-
tzinfo (~> 0.3.29)
|
25
|
-
activeresource (3.2.1)
|
26
|
-
activemodel (= 3.2.1)
|
27
|
-
activesupport (= 3.2.1)
|
28
|
-
activesupport (3.2.1)
|
29
|
-
i18n (~> 0.6)
|
30
|
-
multi_json (~> 1.0)
|
31
|
-
arel (3.0.0)
|
32
|
-
builder (3.0.0)
|
33
|
-
carrierwave (0.5.8)
|
34
|
-
activesupport (~> 3.0)
|
35
|
-
diff-lcs (1.1.3)
|
36
|
-
erubis (2.7.0)
|
37
|
-
hike (1.2.1)
|
38
|
-
i18n (0.6.0)
|
39
|
-
journey (1.0.1)
|
40
|
-
json (1.6.5)
|
41
|
-
mail (2.4.1)
|
42
|
-
i18n (>= 0.4.0)
|
43
|
-
mime-types (~> 1.16)
|
44
|
-
treetop (~> 1.4.8)
|
45
|
-
metaclass (0.0.1)
|
46
|
-
mime-types (1.17.2)
|
47
|
-
mini_magick (3.4)
|
48
|
-
subexec (~> 0.2.1)
|
49
|
-
mocha (0.10.0)
|
50
|
-
metaclass (~> 0.0.1)
|
51
|
-
multi_json (1.0.4)
|
52
|
-
polyglot (0.3.3)
|
53
|
-
rack (1.4.1)
|
54
|
-
rack-cache (1.1)
|
55
|
-
rack (>= 0.4)
|
56
|
-
rack-ssl (1.3.2)
|
57
|
-
rack
|
58
|
-
rack-test (0.6.1)
|
59
|
-
rack (>= 1.0)
|
60
|
-
rails (3.2.1)
|
61
|
-
actionmailer (= 3.2.1)
|
62
|
-
actionpack (= 3.2.1)
|
63
|
-
activerecord (= 3.2.1)
|
64
|
-
activeresource (= 3.2.1)
|
65
|
-
activesupport (= 3.2.1)
|
66
|
-
bundler (~> 1.0)
|
67
|
-
railties (= 3.2.1)
|
68
|
-
railties (3.2.1)
|
69
|
-
actionpack (= 3.2.1)
|
70
|
-
activesupport (= 3.2.1)
|
71
|
-
rack-ssl (~> 1.3.2)
|
72
|
-
rake (>= 0.8.7)
|
73
|
-
rdoc (~> 3.4)
|
74
|
-
thor (~> 0.14.6)
|
75
|
-
rake (0.9.2.2)
|
76
|
-
rdoc (3.12)
|
77
|
-
json (~> 1.4)
|
78
|
-
rest-client (1.6.7)
|
79
|
-
mime-types (>= 1.16)
|
80
|
-
rspec (2.6.0)
|
81
|
-
rspec-core (~> 2.6.0)
|
82
|
-
rspec-expectations (~> 2.6.0)
|
83
|
-
rspec-mocks (~> 2.6.0)
|
84
|
-
rspec-core (2.6.4)
|
85
|
-
rspec-expectations (2.6.0)
|
86
|
-
diff-lcs (~> 1.1.2)
|
87
|
-
rspec-mocks (2.6.0)
|
88
|
-
sprockets (2.1.2)
|
89
|
-
hike (~> 1.2)
|
90
|
-
rack (~> 1.0)
|
91
|
-
tilt (~> 1.1, != 1.3.0)
|
92
|
-
sqlite3 (1.3.5)
|
93
|
-
sqlite3-ruby (1.3.3)
|
94
|
-
sqlite3 (>= 1.3.3)
|
95
|
-
subexec (0.2.1)
|
96
|
-
thor (0.14.6)
|
97
|
-
tilt (1.3.3)
|
98
|
-
treetop (1.4.10)
|
99
|
-
polyglot
|
100
|
-
polyglot (>= 0.3.1)
|
101
|
-
tzinfo (0.3.31)
|
102
|
-
|
103
|
-
PLATFORMS
|
104
|
-
ruby
|
105
|
-
|
106
|
-
DEPENDENCIES
|
107
|
-
carrierwave
|
108
|
-
mini_magick
|
109
|
-
mocha (= 0.10.0)
|
110
|
-
rails
|
111
|
-
rake
|
112
|
-
rest-client
|
113
|
-
rspec (~> 2.6.0)
|
114
|
-
sqlite3-ruby
|