carrierwave-nos 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +2 -0
- data/.rubocop.yml +53 -0
- data/.travis.yml +5 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +74 -0
- data/LICENSE.txt +21 -0
- data/README.md +37 -0
- data/Rakefile +6 -0
- data/carrierwave-nos.gemspec +26 -0
- data/lib/carrierwave-nos.rb +8 -0
- data/lib/carrierwave/nos/bucket.rb +44 -0
- data/lib/carrierwave/nos/configuration.rb +18 -0
- data/lib/carrierwave/nos/nos_client.rb +154 -0
- data/lib/carrierwave/nos/version.rb +5 -0
- data/lib/carrierwave/storage/nos.rb +19 -0
- data/lib/carrierwave/storage/nos_file.rb +39 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 000f41ba6262a1b8f1f6438c92d255e17c37e2f1
|
4
|
+
data.tar.gz: 3087f1ff574e799c82dbc14484d0748b3a6efb0d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cede556d8880b5e2a7baaab1b3bdaf48909998e46c36ca21bb4308055f7195eb86fc18fefc46d1b25abe2101adc421c3a7a5a1c383371bc42801bb6183f838db
|
7
|
+
data.tar.gz: b316520742ed789297a55c1c4fd6ccf695dc8b1e8caa5cc63d36a2ebdc7ce83034c47fd88d440f6b62809d8ffcb7f6de2fe3a9977328f3cae4b6e5a9976e26fc
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
Style/Documentation:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Style/AsciiComments:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Style/IfUnlessModifier:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Style/RedundantSelf:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Style/RaiseArgs:
|
14
|
+
EnforcedStyle: compact
|
15
|
+
|
16
|
+
Style/MutableConstant:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
Metrics/LineLength:
|
20
|
+
Max: 1200
|
21
|
+
|
22
|
+
Metrics/ClassLength:
|
23
|
+
Max: 1200
|
24
|
+
|
25
|
+
Metrics/MethodLength:
|
26
|
+
Max: 1200
|
27
|
+
|
28
|
+
Metrics/ModuleLength:
|
29
|
+
Max: 1200
|
30
|
+
|
31
|
+
Metrics/CyclomaticComplexity:
|
32
|
+
Enabled: false
|
33
|
+
|
34
|
+
Metrics/AbcSize:
|
35
|
+
Enabled: false
|
36
|
+
|
37
|
+
Metrics/PerceivedComplexity:
|
38
|
+
Enabled: false
|
39
|
+
|
40
|
+
Rails/TimeZone:
|
41
|
+
Enabled: false
|
42
|
+
|
43
|
+
Style/GlobalVars:
|
44
|
+
Enabled: false
|
45
|
+
|
46
|
+
Style/GuardClause:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Rails/FindBy:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Rails/HasAndBelongsToMany:
|
53
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
carrierwave-nos (0.1.0)
|
5
|
+
carrierwave (~> 1.0)
|
6
|
+
rest-client
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activemodel (5.0.3)
|
12
|
+
activesupport (= 5.0.3)
|
13
|
+
activerecord (5.0.3)
|
14
|
+
activemodel (= 5.0.3)
|
15
|
+
activesupport (= 5.0.3)
|
16
|
+
arel (~> 7.0)
|
17
|
+
activesupport (5.0.3)
|
18
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
19
|
+
i18n (~> 0.7)
|
20
|
+
minitest (~> 5.1)
|
21
|
+
tzinfo (~> 1.1)
|
22
|
+
arel (7.1.4)
|
23
|
+
carrierwave (1.1.0)
|
24
|
+
activemodel (>= 4.0.0)
|
25
|
+
activesupport (>= 4.0.0)
|
26
|
+
mime-types (>= 1.16)
|
27
|
+
concurrent-ruby (1.0.5)
|
28
|
+
diff-lcs (1.2.5)
|
29
|
+
domain_name (0.5.20170404)
|
30
|
+
unf (>= 0.0.5, < 1.0.0)
|
31
|
+
http-cookie (1.0.3)
|
32
|
+
domain_name (~> 0.5)
|
33
|
+
i18n (0.8.4)
|
34
|
+
mime-types (3.1)
|
35
|
+
mime-types-data (~> 3.2015)
|
36
|
+
mime-types-data (3.2016.0521)
|
37
|
+
minitest (5.10.2)
|
38
|
+
netrc (0.11.0)
|
39
|
+
rest-client (2.0.2)
|
40
|
+
http-cookie (>= 1.0.2, < 2.0)
|
41
|
+
mime-types (>= 1.16, < 4.0)
|
42
|
+
netrc (~> 0.8)
|
43
|
+
rspec (3.4.0)
|
44
|
+
rspec-core (~> 3.4.0)
|
45
|
+
rspec-expectations (~> 3.4.0)
|
46
|
+
rspec-mocks (~> 3.4.0)
|
47
|
+
rspec-core (3.4.4)
|
48
|
+
rspec-support (~> 3.4.0)
|
49
|
+
rspec-expectations (3.4.0)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.4.0)
|
52
|
+
rspec-mocks (3.4.1)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.4.0)
|
55
|
+
rspec-support (3.4.1)
|
56
|
+
sqlite3 (1.3.13)
|
57
|
+
thread_safe (0.3.6)
|
58
|
+
tzinfo (1.2.3)
|
59
|
+
thread_safe (~> 0.1)
|
60
|
+
unf (0.1.4)
|
61
|
+
unf_ext
|
62
|
+
unf_ext (0.0.7.4)
|
63
|
+
|
64
|
+
PLATFORMS
|
65
|
+
ruby
|
66
|
+
|
67
|
+
DEPENDENCIES
|
68
|
+
activerecord
|
69
|
+
carrierwave-nos!
|
70
|
+
rspec (~> 3.0)
|
71
|
+
sqlite3
|
72
|
+
|
73
|
+
BUNDLED WITH
|
74
|
+
1.11.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Shurui Yang
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# CarrierWave for Netease Object Storage Service(NOS)
|
2
|
+
|
3
|
+
This gem adds support for [Netease Object Storage Service](https://c.163.com/product/nos) to [CarrierWave](https://github.com/jnicklas/carrierwave/)
|
4
|
+
|
5
|
+
> NOTE: 此 Gem 是一个 CarrierWave 的组件,你需要配合 CarrierWave 一起使用
|
6
|
+
>
|
7
|
+
> PS: 更多关于网易云对象存储服务的介绍请去[网易蜂巢官网](https://c.163.com/)查看
|
8
|
+
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'carrierwave-nos'
|
14
|
+
```
|
15
|
+
|
16
|
+
## Configuration
|
17
|
+
|
18
|
+
在Rails工程目录下创建文件 `config/initializers/carrierwave.rb` 并填入下面的代码,修改对应的配置:
|
19
|
+
|
20
|
+
```ruby
|
21
|
+
CarrierWave.configure do |config|
|
22
|
+
config.storage = :nos
|
23
|
+
config.nos_access_key = ''
|
24
|
+
config.nos_secret_key = ''
|
25
|
+
# 你需要在 NOS 上面提前创建一个 Bucket
|
26
|
+
config.nos_bucket = ''
|
27
|
+
config.nos_endpoint = 'nos-eastchina1.126.net'
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
参照单元测试`nos_spec.rb`
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
4
|
+
|
5
|
+
require File.expand_path('lib/carrierwave/nos/version')
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'carrierwave-nos'
|
9
|
+
spec.version = CarrierWave::Nos::VERSION
|
10
|
+
spec.authors = ['Shurui Yang']
|
11
|
+
spec.email = ['yangshurui1023@gmail.com']
|
12
|
+
spec.summary = 'NOS support for CarrierWave.'
|
13
|
+
spec.description = 'NOS support for CarrierWave.'
|
14
|
+
spec.homepage = 'https://github.com/yangsr/carrierwave-nos'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_dependency 'carrierwave', ['~> 1.0']
|
21
|
+
spec.add_dependency 'rest-client'
|
22
|
+
|
23
|
+
spec.add_development_dependency 'sqlite3'
|
24
|
+
spec.add_development_dependency 'activerecord'
|
25
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
26
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
require 'carrierwave/nos/bucket'
|
2
|
+
require 'carrierwave/nos/configuration'
|
3
|
+
require 'carrierwave/nos/nos_client'
|
4
|
+
require 'carrierwave/nos/version'
|
5
|
+
require 'carrierwave/storage/nos'
|
6
|
+
require 'carrierwave/storage/nos_file'
|
7
|
+
|
8
|
+
CarrierWave::Uploader::Base.send(:include, CarrierWave::Nos::Configuration)
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module CarrierWave
|
2
|
+
module Nos
|
3
|
+
class Bucket
|
4
|
+
PATH_PREFIX = %r{^/}
|
5
|
+
|
6
|
+
def initialize(uploader)
|
7
|
+
@nos_access_key = uploader.nos_access_key
|
8
|
+
@nos_secret_key = uploader.nos_secret_key
|
9
|
+
@nos_endpoint = uploader.nos_endpoint
|
10
|
+
@nos_bucket = uploader.nos_bucket
|
11
|
+
end
|
12
|
+
|
13
|
+
# 上传文件
|
14
|
+
# params:
|
15
|
+
# - path - remote 存储路径
|
16
|
+
# - file - 需要上传文件的 File 对象
|
17
|
+
# returns:
|
18
|
+
# 图片的下载地址
|
19
|
+
def put(path, file)
|
20
|
+
path.sub!(PATH_PREFIX, '')
|
21
|
+
|
22
|
+
res = oss_upload_client.put_file(file, path)
|
23
|
+
|
24
|
+
if res.code == 200
|
25
|
+
path_to_url(path)
|
26
|
+
else
|
27
|
+
raise 'Put file failed'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# 根据配置返回完整的上传文件的访问地址
|
32
|
+
def path_to_url(path)
|
33
|
+
"https://#{@nos_bucket}.#{@nos_endpoint}/#{path}"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def oss_upload_client
|
39
|
+
return @oss_upload_client if defined?(@oss_upload_client)
|
40
|
+
@oss_upload_client = NosClient.new(@nos_access_key, @nos_secret_key, @nos_bucket, @nos_endpoint)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module CarrierWave
|
2
|
+
module Nos
|
3
|
+
module Configuration
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
add_config :nos_access_key
|
8
|
+
add_config :nos_secret_key
|
9
|
+
add_config :nos_endpoint
|
10
|
+
add_config :nos_bucket
|
11
|
+
|
12
|
+
configure do |config|
|
13
|
+
config.storage_engines[:nos] = 'CarrierWave::Storage::Nos'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'mime/types'
|
2
|
+
require 'rest-client'
|
3
|
+
require 'rexml/document'
|
4
|
+
require 'rexml/xpath'
|
5
|
+
|
6
|
+
module CarrierWave
|
7
|
+
module Nos
|
8
|
+
class NosClient
|
9
|
+
def initialize(access_key, secrete_key, bucket_name, host = 'nos-eastchina1.126.net')
|
10
|
+
@access_key = access_key
|
11
|
+
@secret_key = secrete_key
|
12
|
+
@bucket_name = bucket_name
|
13
|
+
@host = host
|
14
|
+
end
|
15
|
+
|
16
|
+
def put_file(file, object_key)
|
17
|
+
if file.class != File
|
18
|
+
raise ArgumentError.new("File object type needed, but got #{file.class}")
|
19
|
+
end
|
20
|
+
|
21
|
+
resp = if file.size > 100 * 1024 * 1024
|
22
|
+
upload_large_file(file, object_key)
|
23
|
+
else
|
24
|
+
send_request('PUT', @bucket_name, object_key, file)
|
25
|
+
end
|
26
|
+
resp
|
27
|
+
end
|
28
|
+
|
29
|
+
# PUT: send_request('PUT', 'BUCKET_NAME', 'conan.jpg', data)
|
30
|
+
# param: data = File.open(FILE_PATH, 'rb')
|
31
|
+
# GET: send_request('GET', 'BUCKET_NAME', 'conan.jpg', nil)
|
32
|
+
# DELETE: send_request('DELETE', 'BUCKET_NAME', 'conan.jpg', nil)
|
33
|
+
# HEAD: send_request('HEAD', 'BUCKET_NAME', 'conan.jpg', nil)
|
34
|
+
# POST: send_request('POST', 'BUCKET_NAME', "#{object_key}?uploads", nil)
|
35
|
+
# send request and get response
|
36
|
+
def send_request(method, bucket, object_key, data = nil)
|
37
|
+
unless %w[GET DELETE HEAD PUT POST].include?(method)
|
38
|
+
raise ArgumentError.new('Only support following http method: GET DELETE HEAD PUT POST')
|
39
|
+
end
|
40
|
+
if data.nil?
|
41
|
+
content_type = ''
|
42
|
+
else
|
43
|
+
mime = MIME::Types.type_for(object_key).first
|
44
|
+
content_type = if mime.nil?
|
45
|
+
'application/octet-stream'
|
46
|
+
else
|
47
|
+
mime.content_type
|
48
|
+
end
|
49
|
+
end
|
50
|
+
# ruby url encode ignore '/', so replace '/' with '%2f' manually
|
51
|
+
resource = "/#{bucket}/#{URI.encode(object_key).gsub('/', '%2F')}"
|
52
|
+
headers = get_headers(method, resource, content_type, data.nil? ? nil : data.size)
|
53
|
+
url = "#{@bucket_name}.#{@host}" + "/#{URI.encode(object_key).gsub('/', '%2F')}"
|
54
|
+
|
55
|
+
if method == 'PUT'
|
56
|
+
res = RestClient.put(url, data, headers)
|
57
|
+
elsif method == 'GET'
|
58
|
+
res = RestClient.get(url, headers)
|
59
|
+
elsif method == 'DELETE'
|
60
|
+
res = RestClient.delete(url, headers)
|
61
|
+
elsif method == 'HEAD'
|
62
|
+
res = RestClient.head(url, headers)
|
63
|
+
elsif method == 'POST'
|
64
|
+
res = RestClient.post(url, data, headers)
|
65
|
+
end
|
66
|
+
|
67
|
+
res
|
68
|
+
end
|
69
|
+
|
70
|
+
def upload_large_file(file, object_key)
|
71
|
+
upload_id = init_multi_upload(object_key)
|
72
|
+
if upload_id == false
|
73
|
+
return 400
|
74
|
+
end
|
75
|
+
part_size = 50 * 1024 * 1024
|
76
|
+
part_num = 1
|
77
|
+
part_info = {}
|
78
|
+
until file.eof?
|
79
|
+
part_data = file.read(part_size)
|
80
|
+
etag = upload_part(object_key, part_num, upload_id, part_data)
|
81
|
+
if etag != false
|
82
|
+
part_info[part_num] = etag
|
83
|
+
part_num += 1
|
84
|
+
else
|
85
|
+
return 400
|
86
|
+
end
|
87
|
+
end
|
88
|
+
complete_multi_upload(object_key, upload_id, part_info)
|
89
|
+
end
|
90
|
+
|
91
|
+
def init_multi_upload(object_key)
|
92
|
+
resp = send_request('POST', @bucket_name, "#{object_key}?uploads", nil)
|
93
|
+
if resp.code == 200
|
94
|
+
doc = REXML::Document.new(resp.body)
|
95
|
+
upload_id = REXML::XPath.first(doc, '//UploadId/text()')
|
96
|
+
return upload_id
|
97
|
+
else
|
98
|
+
return false
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def upload_part(object_key, part_num, upload_id, data)
|
103
|
+
resp = send_request('PUT', @bucket_name, "#{object_key}?partNumber=#{part_num}&uploadId=#{upload_id}", data)
|
104
|
+
if resp.code == 200
|
105
|
+
return resp.headers[:etag]
|
106
|
+
else
|
107
|
+
return false
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
def complete_multi_upload(object_key, upload_id, part_info)
|
112
|
+
data = '<CompleteMultipartUpload>'
|
113
|
+
part_info.each do |part_num, etag|
|
114
|
+
data += "<Part><PartNumber>#{part_num}</PartNumber><ETag>#{etag}</ETag></Part>"
|
115
|
+
end
|
116
|
+
data += '</CompleteMultipartUpload>'
|
117
|
+
send_request('POST', @bucket_name, "#{object_key}?uploadId=#{upload_id}", data)
|
118
|
+
end
|
119
|
+
|
120
|
+
private
|
121
|
+
|
122
|
+
def get_headers(method, resource, content_type = '', content_length = nil)
|
123
|
+
date = Time.now.httpdate
|
124
|
+
headers = {
|
125
|
+
'Authorization' => get_authorization(method, resource, date, content_type),
|
126
|
+
'Date' => date,
|
127
|
+
'Host' => "#{@bucket_name}.#{@host}"
|
128
|
+
}
|
129
|
+
unless content_type.nil?
|
130
|
+
headers['Content-Type'] = content_type
|
131
|
+
end
|
132
|
+
unless content_length.nil?
|
133
|
+
headers['Content-Length'] = content_length
|
134
|
+
end
|
135
|
+
|
136
|
+
headers
|
137
|
+
end
|
138
|
+
|
139
|
+
def get_authorization(method, resource, date, content_type = '')
|
140
|
+
content = {
|
141
|
+
'http_verb' => method,
|
142
|
+
'content_md5' => '',
|
143
|
+
'content_type' => content_type,
|
144
|
+
'date' => date,
|
145
|
+
'canonicalized_resource' => resource,
|
146
|
+
}
|
147
|
+
str_to_sign = content.values.join("\n")
|
148
|
+
signature = Base64.encode64(OpenSSL::HMAC.digest('sha256', @secret_key, str_to_sign))
|
149
|
+
|
150
|
+
"NOS #{@access_key}:#{signature}"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'carrierwave'
|
4
|
+
|
5
|
+
module CarrierWave
|
6
|
+
module Storage
|
7
|
+
class Nos < Abstract
|
8
|
+
def store!(file)
|
9
|
+
f = NosFile.new(uploader, self, uploader.store_path)
|
10
|
+
f.store(::File.open(file.file))
|
11
|
+
f
|
12
|
+
end
|
13
|
+
|
14
|
+
def retrieve!(identifier)
|
15
|
+
NosFile.new(uploader, self, uploader.store_path(identifier))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module CarrierWave
|
2
|
+
module Storage
|
3
|
+
class NosFile < CarrierWave::SanitizedFile
|
4
|
+
attr_reader :path
|
5
|
+
|
6
|
+
def initialize(uploader, base, path)
|
7
|
+
@uploader = uploader
|
8
|
+
@base = base
|
9
|
+
@path = URI.encode(path)
|
10
|
+
end
|
11
|
+
|
12
|
+
def read
|
13
|
+
object = bucket.get(@path)
|
14
|
+
@headers = object.headers
|
15
|
+
object
|
16
|
+
end
|
17
|
+
|
18
|
+
def store(file)
|
19
|
+
bucket.put(@path, file)
|
20
|
+
end
|
21
|
+
|
22
|
+
def url(_opts = {})
|
23
|
+
bucket.path_to_url(@path)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def headers
|
29
|
+
@headers ||= {}
|
30
|
+
end
|
31
|
+
|
32
|
+
def bucket
|
33
|
+
return @bucket if defined? @bucket
|
34
|
+
|
35
|
+
@bucket = CarrierWave::Nos::Bucket.new(@uploader)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: carrierwave-nos
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shurui Yang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: carrierwave
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: NOS support for CarrierWave.
|
84
|
+
email:
|
85
|
+
- yangshurui1023@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- Gemfile.lock
|
96
|
+
- LICENSE.txt
|
97
|
+
- README.md
|
98
|
+
- Rakefile
|
99
|
+
- carrierwave-nos.gemspec
|
100
|
+
- lib/carrierwave-nos.rb
|
101
|
+
- lib/carrierwave/nos/bucket.rb
|
102
|
+
- lib/carrierwave/nos/configuration.rb
|
103
|
+
- lib/carrierwave/nos/nos_client.rb
|
104
|
+
- lib/carrierwave/nos/version.rb
|
105
|
+
- lib/carrierwave/storage/nos.rb
|
106
|
+
- lib/carrierwave/storage/nos_file.rb
|
107
|
+
homepage: https://github.com/yangsr/carrierwave-nos
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.5.1
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: NOS support for CarrierWave.
|
131
|
+
test_files: []
|