carrierwave-aliyun 0.1.0 → 0.1.1

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/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  uploads
2
+ *.gem
data/Changelogs.md ADDED
@@ -0,0 +1,8 @@
1
+ ## 0.1.1
2
+
3
+ * 修改 Aliyun OSS 的请求地址.
4
+ * 加入可选项,使用 Aliyun 内部地址调用上传,以提高内部网络使用的速度.
5
+
6
+ ## 0.1.0
7
+
8
+ * 功能实现.
data/README.md CHANGED
@@ -4,23 +4,29 @@ This gem adds support for [Aliyun OSS](http://oss.aliyun.com) to [CarrierWave](h
4
4
 
5
5
  ## Installation
6
6
 
7
- gem install carrierwave-aliyun
7
+ ```bash
8
+ gem install carrierwave-aliyun
9
+ ```
8
10
 
9
11
  ## Using Bundler
10
12
 
11
- gem 'rest-client'
12
- gem 'carrierwave-aliyun'
13
+ ```ruby
14
+ gem 'rest-client'
15
+ gem 'carrierwave-aliyun'
16
+ ```
13
17
 
14
18
  ## Configuration
15
19
 
16
- You'll need to configure the to use this in config/initializes/carrierwave.rb
20
+ 创建这么个脚本 `config/initializes/carrierwave.rb` 填入下面的代码,并修改对应的配置:
17
21
 
18
22
  ```ruby
19
23
  CarrierWave.configure do |config|
20
24
  config.storage = :aliyun
21
25
  config.aliyun_access_id = "xxxxxx"
22
26
  config.aliyun_access_key = 'xxxxxx'
23
- # you need create this bucket first!
27
+ # 你需要在 Aliyum OSS 上面提前创建一个 Bucket
24
28
  config.aliyun_bucket = "simple"
29
+ # 是否使用内部连接,true - 使用 Aliyun 局域网的方式访问 false - 外部网络访问
30
+ config.aliyun_internal = true
25
31
  end
26
32
  ```
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "carrierwave-aliyun"
6
- s.version = "0.1.0"
6
+ s.version = "0.1.1"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Jason Lee"]
9
9
  s.email = ["huacnlee@gmail.com"]
@@ -17,6 +17,4 @@ Gem::Specification.new do |s|
17
17
 
18
18
  s.add_dependency "carrierwave", [">= 0.5.7"]
19
19
  s.add_dependency "rest-client", [">= 1.6.7"]
20
- s.add_development_dependency "rspec", ["~> 2.6"]
21
- s.add_development_dependency "rake", ["~> 0.9"]
22
20
  end
@@ -6,6 +6,7 @@ module CarrierWave
6
6
  add_config :aliyun_access_id
7
7
  add_config :aliyun_access_key
8
8
  add_config :aliyun_bucket
9
+ add_config :aliyun_internal
9
10
  end
10
11
  end
11
12
 
@@ -13,6 +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
+ @aliyun_host = "oss.aliyuncs.com"
17
+ if options[:aliyun_internal] == true
18
+ @aliyun_host = "oss-internal.aliyuncs.com"
19
+ end
16
20
  end
17
21
 
18
22
  def put(path, file)
@@ -20,14 +24,14 @@ module CarrierWave
20
24
  content_type = "image/jpg"
21
25
  date = Time.now.gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT")
22
26
  path = "#{@aliyun_bucket}/#{path}"
23
- url = "http://storage.aliyun.com/#{path}"
27
+ url = "http://#{@aliyun_host}/#{path}"
24
28
  auth_sign = sign("PUT", path, content_md5, content_type ,date)
25
29
  headers = {
26
30
  "Authorization" => auth_sign,
27
31
  "Content-Type" => content_type,
28
32
  "Content-Length" => file.length,
29
33
  "Date" => date,
30
- "Host" => "storage.aliyun.com",
34
+ "Host" => @aliyun_host,
31
35
  "Expect" => "100-Continue"
32
36
  }
33
37
  response = RestClient.put(url, file, headers)
@@ -93,7 +97,7 @@ module CarrierWave
93
97
  end
94
98
 
95
99
  def url
96
- "http://storage.aliyun.com/#{@uploader.aliyun_bucket}/#{@path}"
100
+ "http://oss.aliyuncs.com/#{@uploader.aliyun_bucket}/#{@path}"
97
101
  end
98
102
 
99
103
  def store(data)
@@ -113,13 +117,14 @@ module CarrierWave
113
117
  def oss_connection
114
118
  return @oss_connection if @oss_connection
115
119
 
116
- config = {:aliyun_access_id => @uploader.aliyun_access_id,
120
+ config = {
121
+ :aliyun_access_id => @uploader.aliyun_access_id,
117
122
  :aliyun_access_key => @uploader.aliyun_access_key,
118
123
  :aliyun_bucket => @uploader.aliyun_bucket
119
124
  }
120
125
  @oss_connection ||= CarrierWave::Storage::Aliyun::Connection.new(config)
121
126
  end
122
-
127
+
123
128
  end
124
129
 
125
130
  def store!(file)
data/spec/spec_helper.rb CHANGED
@@ -29,6 +29,7 @@ CarrierWave.configure do |config|
29
29
  config.aliyun_access_id = "7ewl4zm3mhi45vko9zx022ul"
30
30
  config.aliyun_access_key = 'Ajpi7IRKDKdXYHHFFoS89uQJQE8='
31
31
  config.aliyun_bucket = "carrierwave"
32
+ # config.aliyun_internal = false
32
33
  end
33
34
 
34
35
  def load_file(fname)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-aliyun
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-14 00:00:00.000000000 Z
12
+ date: 2012-11-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: carrierwave
16
- requirement: &70172009111240 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,40 +21,28 @@ dependencies:
21
21
  version: 0.5.7
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70172009111240
25
- - !ruby/object:Gem::Dependency
26
- name: rest-client
27
- requirement: &70172009110740 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
28
25
  none: false
29
26
  requirements:
30
27
  - - ! '>='
31
28
  - !ruby/object:Gem::Version
32
- version: 1.6.7
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *70172009110740
29
+ version: 0.5.7
36
30
  - !ruby/object:Gem::Dependency
37
- name: rspec
38
- requirement: &70172009110260 !ruby/object:Gem::Requirement
31
+ name: rest-client
32
+ requirement: !ruby/object:Gem::Requirement
39
33
  none: false
40
34
  requirements:
41
- - - ~>
35
+ - - ! '>='
42
36
  - !ruby/object:Gem::Version
43
- version: '2.6'
44
- type: :development
37
+ version: 1.6.7
38
+ type: :runtime
45
39
  prerelease: false
46
- version_requirements: *70172009110260
47
- - !ruby/object:Gem::Dependency
48
- name: rake
49
- requirement: &70172009109780 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
50
41
  none: false
51
42
  requirements:
52
- - - ~>
43
+ - - ! '>='
53
44
  - !ruby/object:Gem::Version
54
- version: '0.9'
55
- type: :development
56
- prerelease: false
57
- version_requirements: *70172009109780
45
+ version: 1.6.7
58
46
  description: Aliyun OSS support for Carrierwave
59
47
  email:
60
48
  - huacnlee@gmail.com
@@ -64,6 +52,7 @@ extra_rdoc_files: []
64
52
  files:
65
53
  - .gitignore
66
54
  - .rspec
55
+ - Changelogs.md
67
56
  - Gemfile
68
57
  - Gemfile.lock
69
58
  - README.md
@@ -95,7 +84,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
84
  version: '0'
96
85
  requirements: []
97
86
  rubyforge_project:
98
- rubygems_version: 1.8.10
87
+ rubygems_version: 1.8.24
99
88
  signing_key:
100
89
  specification_version: 3
101
90
  summary: Aliyun OSS support for Carrierwave
@@ -104,3 +93,4 @@ test_files:
104
93
  - spec/foo.jpg
105
94
  - spec/spec_helper.rb
106
95
  - spec/upload_spec.rb
96
+ has_rdoc: