carrierwave-qiniu 0.1.5 → 0.1.8
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +7 -1
- data/carrierwave-qiniu.gemspec +1 -1
- data/lib/carrierwave-qiniu/version.rb +1 -1
- data/lib/carrierwave/qiniu/configuration.rb +2 -0
- data/lib/carrierwave/storage/qiniu.rb +33 -7
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ccbd315d40ee92225c01233111bb7fe0dba63bf6
|
4
|
+
data.tar.gz: f971548c853f9e1969e7c2154bcdd772f01ffc94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3eef04296696a3088e96ea06e0cb2b813c4f7235a6b9d64ba89164c4a386a61c21fc96c027a6d148320fb856010c9b9b3e2887718531098c34e8b96e99224893
|
7
|
+
data.tar.gz: ce454ab4c3af772794e92703576a167df5c1a802e2d0e67cf34164262e6372663ffecf35010cd8af101b67dd80826c028994ef82f8de0670dd46d6c8ae172ae3
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
|
2
|
+
## CHANGE LOG
|
3
|
+
|
4
|
+
### v0.1.7
|
5
|
+
|
6
|
+
- 添加从云端读取(下载)文件 。 [https://github.com/huobazi/carrierwave-qiniu/pull/27](https://github.com/huobazi/carrierwave-qiniu/pull/27)
|
7
|
+
|
8
|
+
- 增加获取有时效性url链接地址的方法 。 [https://github.com/huobazi/carrierwave-qiniu/issues/25](https://github.com/huobazi/carrierwave-qiniu/issues/25)
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Carrierwave::Qiniu
|
2
2
|
|
3
|
-
[](http://badge.fury.io/rb/carrierwave-qiniu)
|
4
4
|
|
5
5
|
This gem adds storage support for [Qiniu](http://qiniutek.com) to [Carrierwave](https://github.com/jnicklas/carrierwave)
|
6
6
|
example: https://github.com/huobazi/carrierwave-qiniu-example
|
@@ -33,6 +33,8 @@ You'll need to configure it in config/initializes/carrierwave.rb
|
|
33
33
|
config.qiniu_bucket_private= true #default is false
|
34
34
|
config.qiniu_block_size = 4*1024*1024
|
35
35
|
config.qiniu_protocol = "http"
|
36
|
+
|
37
|
+
config.qiniu_up_host = 'http://up.qiniug.com' #七牛上传海外服务器,国内使用可以不要这行配置
|
36
38
|
end
|
37
39
|
```
|
38
40
|
|
@@ -87,3 +89,7 @@ or see the spec test on https://github.com/huobazi/carrierwave-qiniu/blob/master
|
|
87
89
|
## Contributors
|
88
90
|
|
89
91
|
See the [Contributors List](https://github.com/huobazi/carrierwave-qiniu/graphs/contributors).
|
92
|
+
|
93
|
+
## CHANGE LOG
|
94
|
+
|
95
|
+
See the [CHANGELOGS.md](https://github.com/huobazi/carrierwave-qiniu/blob/master/CHANGELOG.md).
|
data/carrierwave-qiniu.gemspec
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'carrierwave'
|
3
3
|
require 'qiniu'
|
4
|
+
require 'qiniu/http'
|
4
5
|
|
5
6
|
module CarrierWave
|
6
7
|
module Storage
|
@@ -18,6 +19,8 @@ module CarrierWave
|
|
18
19
|
@qiniu_async_ops = options[:qiniu_async_ops] || ''
|
19
20
|
@qiniu_can_overwrite = options[:qiniu_can_overwrite] || false
|
20
21
|
@qiniu_expires_in = options[:qiniu_expires_in] || options[:expires_in] || 3600
|
22
|
+
@qiniu_up_host = options[:qiniu_up_host]
|
23
|
+
@qiniu_private_url_expires_in = options[:qiniu_private_url_expires_in] || 3600
|
21
24
|
init
|
22
25
|
end
|
23
26
|
|
@@ -54,10 +57,17 @@ module CarrierWave
|
|
54
57
|
code == 200 ? result : {}
|
55
58
|
end
|
56
59
|
|
60
|
+
def get(path)
|
61
|
+
code, result, response_headers = ::Qiniu::HTTP.get( download_url(path) )
|
62
|
+
code == 200 ? result : nil
|
63
|
+
end
|
64
|
+
|
57
65
|
def download_url(path)
|
66
|
+
private_url_args = {}
|
58
67
|
encode_path = URI.escape(path, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) #fix chinese file name, same as encodeURIComponent in js
|
59
68
|
primitive_url = "#{@qiniu_protocol}://#{@qiniu_bucket_domain}/#{encode_path}"
|
60
|
-
|
69
|
+
private_url_args.merge!(expires_in: @qiniu_private_url_expires_in) if @qiniu_bucket_private
|
70
|
+
@qiniu_bucket_private ? ::Qiniu::Auth.authorize_download_url(primitive_url, private_url_args) : primitive_url
|
61
71
|
end
|
62
72
|
|
63
73
|
private
|
@@ -67,13 +77,16 @@ module CarrierWave
|
|
67
77
|
end
|
68
78
|
|
69
79
|
def init_qiniu_rs_connection
|
70
|
-
|
71
|
-
|
72
|
-
::Qiniu.establish_connection! :access_key => @qiniu_access_key,
|
80
|
+
options = {
|
81
|
+
:access_key => @qiniu_access_key,
|
73
82
|
:secret_key => @qiniu_secret_key,
|
74
|
-
:
|
83
|
+
:user_agent => 'CarrierWave-Qiniu/' + Carrierwave::Qiniu::VERSION + ' ('+RUBY_PLATFORM+')' + ' Ruby/'+ RUBY_VERSION
|
84
|
+
}
|
85
|
+
options.merge(:block_size => @qiniu_block_size) if @qiniu_block_size
|
86
|
+
options.merge(:up_host => @qiniu_up_host) if @qiniu_up_host
|
87
|
+
|
88
|
+
::Qiniu.establish_connection! options
|
75
89
|
|
76
|
-
@qiniu_rs_connection_inited = true
|
77
90
|
end
|
78
91
|
|
79
92
|
end
|
@@ -100,6 +113,17 @@ module CarrierWave
|
|
100
113
|
qiniu_connection.delete(@path)
|
101
114
|
end
|
102
115
|
|
116
|
+
##
|
117
|
+
# Reads the contents of the file from Cloud Files
|
118
|
+
#
|
119
|
+
# === Returns
|
120
|
+
#
|
121
|
+
# [String] contents of the file
|
122
|
+
#
|
123
|
+
def read
|
124
|
+
qiniu_connection.get(@path) if self.size > 0
|
125
|
+
end
|
126
|
+
|
103
127
|
def content_type
|
104
128
|
file_info['mimeType'] || 'application/octet-stream'
|
105
129
|
end
|
@@ -122,7 +146,9 @@ module CarrierWave
|
|
122
146
|
:qiniu_bucket_private=> @uploader.qiniu_bucket_private,
|
123
147
|
:qiniu_block_size => @uploader.qiniu_block_size,
|
124
148
|
:qiniu_protocol => @uploader.qiniu_protocol,
|
125
|
-
:qiniu_expires_in => @uploader.qiniu_expires_in
|
149
|
+
:qiniu_expires_in => @uploader.qiniu_expires_in,
|
150
|
+
:qiniu_up_host => @uploader.qiniu_up_host,
|
151
|
+
:qiniu_private_url_expires_in => @uploader.qiniu_private_url_expires_in
|
126
152
|
}
|
127
153
|
|
128
154
|
if @uploader.respond_to?(:qiniu_async_ops) and !@uploader.qiniu_async_ops.nil? and @uploader.qiniu_async_ops.size > 0
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carrierwave-qiniu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marble Wu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carrierwave
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 6.2
|
33
|
+
version: 6.4.2
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 6.2
|
40
|
+
version: 6.4.2
|
41
41
|
description: Qiniu Storage support for CarrierWave
|
42
42
|
email:
|
43
43
|
- huobazi@gmail.com
|
@@ -46,6 +46,7 @@ extensions: []
|
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
48
|
- ".gitignore"
|
49
|
+
- CHANGELOG.md
|
49
50
|
- Gemfile
|
50
51
|
- LICENSE
|
51
52
|
- README.md
|
@@ -78,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
79
|
version: '0'
|
79
80
|
requirements: []
|
80
81
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.4.6
|
82
83
|
signing_key:
|
83
84
|
specification_version: 4
|
84
85
|
summary: Qiniu Storage support for CarrierWave
|