carrierwave-aliyun 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelogs.md +4 -0
- data/README.md +3 -0
- data/lib/carrierwave/aliyun/configuration.rb +1 -0
- data/lib/carrierwave/aliyun/version.rb +1 -1
- data/lib/carrierwave/storage/aliyun.rb +12 -9
- data/spec/aliyun_spec.rb +17 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66ec3f177151654773bc1eddd296f93c79832fab
|
4
|
+
data.tar.gz: c9f0a7b23e521a236139992f8b0c08034335a80b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2b0e87655cc012e33a7c5741ac6a30207bc950ebc201135eb2df49e7f0f419bc290665a7c99c08ee65de70c418a727dff2b7eb1b35e4ddb261b37e6ea495f0c4
|
7
|
+
data.tar.gz: 2be951bd4e828cecd28650a31b08950ea7d2b84b77ac430c7b6b7f66a8363f3563196b0fef69d48b1e6ce968a06e3ff6d35fb207c9a9be9991f0c5129e745fa0
|
data/Changelogs.md
CHANGED
data/README.md
CHANGED
@@ -28,6 +28,9 @@ CarrierWave.configure do |config|
|
|
28
28
|
config.aliyun_bucket = "simple"
|
29
29
|
# 是否使用内部连接,true - 使用 Aliyun 局域网的方式访问 false - 外部网络访问
|
30
30
|
config.aliyun_internal = true
|
31
|
+
# 使用自定义域名,设定此项,carrierwave 返回的 URL 将会用自定义域名
|
32
|
+
# 自定于域名请 CNAME 到 you_bucket_name.oss.aliyuncs.com (you_bucket_name 是你的 bucket 的名称)
|
33
|
+
config.aliyun_host = "foo.bar.com"
|
31
34
|
end
|
32
35
|
```
|
33
36
|
|
@@ -13,9 +13,10 @@ module CarrierWave
|
|
13
13
|
@aliyun_access_id = options[:aliyun_access_id]
|
14
14
|
@aliyun_access_key = options[:aliyun_access_key]
|
15
15
|
@aliyun_bucket = options[:aliyun_bucket]
|
16
|
-
@
|
16
|
+
@aliyun_upload_host = "oss.aliyuncs.com"
|
17
|
+
@aliyun_host = options[:aliyun_host] || @aliyun_upload_host
|
17
18
|
if options[:aliyun_internal] == true
|
18
|
-
@
|
19
|
+
@aliyun_upload_host = "oss-internal.aliyuncs.com"
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
@@ -31,24 +32,24 @@ module CarrierWave
|
|
31
32
|
"Content-Type" => content_type,
|
32
33
|
"Content-Length" => file_data.length,
|
33
34
|
"Date" => date,
|
34
|
-
"Host" => @
|
35
|
+
"Host" => @aliyun_upload_host,
|
35
36
|
"Expect" => "100-Continue"
|
36
37
|
}
|
37
38
|
response = RestClient.put(url, file_data, headers)
|
38
|
-
return
|
39
|
+
return path_to_url(path, :get => true)
|
39
40
|
end
|
40
41
|
|
41
42
|
def delete(path)
|
42
43
|
path = format_path(path)
|
43
44
|
date = gmtdate
|
44
45
|
headers = {
|
45
|
-
"Host" => @
|
46
|
+
"Host" => @aliyun_upload_host,
|
46
47
|
"Date" => date,
|
47
48
|
"Authorization" => sign("DELETE", path, "", "" ,date)
|
48
49
|
}
|
49
50
|
url = path_to_url(path)
|
50
51
|
RestClient.delete(url, headers)
|
51
|
-
return
|
52
|
+
return path_to_url(path, :get => true)
|
52
53
|
end
|
53
54
|
|
54
55
|
def gmtdate
|
@@ -61,8 +62,10 @@ module CarrierWave
|
|
61
62
|
[@aliyun_bucket, path].join("/")
|
62
63
|
end
|
63
64
|
|
64
|
-
def path_to_url(path)
|
65
|
-
|
65
|
+
def path_to_url(path, opts = {})
|
66
|
+
host = @aliyun_upload_host
|
67
|
+
host = @aliyun_host if opts[:get]
|
68
|
+
"http://#{host}/#{path}"
|
66
69
|
end
|
67
70
|
|
68
71
|
private
|
@@ -122,7 +125,7 @@ module CarrierWave
|
|
122
125
|
end
|
123
126
|
|
124
127
|
def url
|
125
|
-
"http
|
128
|
+
"http://#{@uploader.aliyun_host}/#{@uploader.aliyun_bucket}/#{@path}"
|
126
129
|
end
|
127
130
|
|
128
131
|
def store(data, opts = {})
|
data/spec/aliyun_spec.rb
CHANGED
@@ -4,26 +4,38 @@ require "net/http"
|
|
4
4
|
|
5
5
|
describe "Aliyun" do
|
6
6
|
before(:all) do
|
7
|
-
opts = {
|
7
|
+
@opts = {
|
8
8
|
:aliyun_access_id => ALIYUN_ACCESS_ID,
|
9
9
|
:aliyun_access_key => ALIYUN_ACCESS_KEY,
|
10
10
|
:aliyun_bucket => ALIYUN_BUCKET
|
11
11
|
}
|
12
|
-
@connection = CarrierWave::Storage::Aliyun::Connection.new(opts)
|
12
|
+
@connection = CarrierWave::Storage::Aliyun::Connection.new(@opts)
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
it "should put" do
|
16
16
|
url = @connection.put("a/a.jpg",load_file("foo.jpg").read)
|
17
17
|
Net::HTTP.get_response(URI.parse(url)).code.should == "200"
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it "should put with / prefix" do
|
21
21
|
url = @connection.put("/a/a.jpg",load_file("foo.jpg").read)
|
22
22
|
Net::HTTP.get_response(URI.parse(url)).code.should == "200"
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
it "should delete" do
|
26
26
|
url = @connection.delete("/a/a.jpg")
|
27
27
|
Net::HTTP.get_response(URI.parse(url)).code.should == "404"
|
28
28
|
end
|
29
|
+
|
30
|
+
it "should use default domain" do
|
31
|
+
url = @connection.put("a/a.jpg",load_file("foo.jpg").read)
|
32
|
+
url.should == "http://oss.aliyuncs.com/#{ALIYUN_BUCKET}/a/a.jpg"
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should support custom domain" do
|
36
|
+
@opts[:aliyun_host] = "foo.bar.com"
|
37
|
+
@connection = CarrierWave::Storage::Aliyun::Connection.new(@opts)
|
38
|
+
url = @connection.put("a/a.jpg",load_file("foo.jpg").read)
|
39
|
+
url.should == "http://foo.bar.com/#{ALIYUN_BUCKET}/a/a.jpg"
|
40
|
+
end
|
29
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.1.
|
4
|
+
version: 0.1.5
|
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-03
|
11
|
+
date: 2013-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
@@ -81,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
81
81
|
version: '0'
|
82
82
|
requirements: []
|
83
83
|
rubyforge_project:
|
84
|
-
rubygems_version: 2.0.
|
84
|
+
rubygems_version: 2.0.0
|
85
85
|
signing_key:
|
86
86
|
specification_version: 4
|
87
87
|
summary: Aliyun OSS support for Carrierwave
|