aliyun-oss-sdk 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +191 -0
- data/README.md +13 -1
- data/lib/aliyun/oss.rb +0 -1
- data/lib/aliyun/oss/client.rb +9 -3
- data/lib/aliyun/oss/http.rb +13 -6
- data/lib/aliyun/oss/rule/cors.rb +3 -1
- data/lib/aliyun/oss/rule/lifecycle.rb +6 -1
- data/lib/aliyun/oss/utils.rb +3 -2
- data/lib/aliyun/oss/version.rb +1 -1
- data/wiki/bucket.md +106 -0
- data/wiki/cors.md +0 -0
- data/wiki/error.md +0 -0
- data/wiki/get_start.md +67 -0
- data/wiki/installation.md +15 -0
- data/wiki/lifecycle.md +0 -0
- data/wiki/multipart.md +24 -0
- data/wiki/object.md +74 -0
- metadata +10 -2
- data/lib/aliyun/oss/xml_builder.rb +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbccd13ad8cbf7ce3e840808e7065fad629020d9
|
4
|
+
data.tar.gz: b375cc54baf8f421deedadf54ba3fa0bac695172
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 624ca57c96e66016198632a1bf199c2884c103a0f6d7ee9ba6352fbb3839152ef40ac3c12d0626c12ba33464a7ed839ba55dfb449e2af0f815cdbd5e0d040202
|
7
|
+
data.tar.gz: a89b46e78d75d569748c50e812b2e0d2c55e3071a19c7a7c1827d07cfe81565839c856ddada590a546ce3e878e747694970cbe3c89c2c6c90a05f30eb4c2afa8
|
data/LICENSE
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction, and
|
10
|
+
distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
13
|
+
owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities
|
16
|
+
that control, are controlled by, or are under common control with that entity.
|
17
|
+
For the purposes of this definition, "control" means (i) the power, direct or
|
18
|
+
indirect, to cause the direction or management of such entity, whether by
|
19
|
+
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
20
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
21
|
+
|
22
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
23
|
+
permissions granted by this License.
|
24
|
+
|
25
|
+
"Source" form shall mean the preferred form for making modifications, including
|
26
|
+
but not limited to software source code, documentation source, and configuration
|
27
|
+
files.
|
28
|
+
|
29
|
+
"Object" form shall mean any form resulting from mechanical transformation or
|
30
|
+
translation of a Source form, including but not limited to compiled object code,
|
31
|
+
generated documentation, and conversions to other media types.
|
32
|
+
|
33
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
34
|
+
available under the License, as indicated by a copyright notice that is included
|
35
|
+
in or attached to the work (an example is provided in the Appendix below).
|
36
|
+
|
37
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
38
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
39
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
40
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
41
|
+
shall not include works that remain separable from, or merely link (or bind by
|
42
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
43
|
+
|
44
|
+
"Contribution" shall mean any work of authorship, including the original version
|
45
|
+
of the Work and any modifications or additions to that Work or Derivative Works
|
46
|
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
47
|
+
by the copyright owner or by an individual or Legal Entity authorized to submit
|
48
|
+
on behalf of the copyright owner. For the purposes of this definition,
|
49
|
+
"submitted" means any form of electronic, verbal, or written communication sent
|
50
|
+
to the Licensor or its representatives, including but not limited to
|
51
|
+
communication on electronic mailing lists, source code control systems, and
|
52
|
+
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
53
|
+
the purpose of discussing and improving the Work, but excluding communication
|
54
|
+
that is conspicuously marked or otherwise designated in writing by the copyright
|
55
|
+
owner as "Not a Contribution."
|
56
|
+
|
57
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
58
|
+
of whom a Contribution has been received by Licensor and subsequently
|
59
|
+
incorporated within the Work.
|
60
|
+
|
61
|
+
2. Grant of Copyright License.
|
62
|
+
|
63
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
64
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
65
|
+
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
66
|
+
publicly display, publicly perform, sublicense, and distribute the Work and such
|
67
|
+
Derivative Works in Source or Object form.
|
68
|
+
|
69
|
+
3. Grant of Patent License.
|
70
|
+
|
71
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
72
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
73
|
+
irrevocable (except as stated in this section) patent license to make, have
|
74
|
+
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
75
|
+
such license applies only to those patent claims licensable by such Contributor
|
76
|
+
that are necessarily infringed by their Contribution(s) alone or by combination
|
77
|
+
of their Contribution(s) with the Work to which such Contribution(s) was
|
78
|
+
submitted. If You institute patent litigation against any entity (including a
|
79
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
80
|
+
Contribution incorporated within the Work constitutes direct or contributory
|
81
|
+
patent infringement, then any patent licenses granted to You under this License
|
82
|
+
for that Work shall terminate as of the date such litigation is filed.
|
83
|
+
|
84
|
+
4. Redistribution.
|
85
|
+
|
86
|
+
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
87
|
+
in any medium, with or without modifications, and in Source or Object form,
|
88
|
+
provided that You meet the following conditions:
|
89
|
+
|
90
|
+
You must give any other recipients of the Work or Derivative Works a copy of
|
91
|
+
this License; and
|
92
|
+
You must cause any modified files to carry prominent notices stating that You
|
93
|
+
changed the files; and
|
94
|
+
You must retain, in the Source form of any Derivative Works that You distribute,
|
95
|
+
all copyright, patent, trademark, and attribution notices from the Source form
|
96
|
+
of the Work, excluding those notices that do not pertain to any part of the
|
97
|
+
Derivative Works; and
|
98
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
99
|
+
Derivative Works that You distribute must include a readable copy of the
|
100
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
101
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
102
|
+
following places: within a NOTICE text file distributed as part of the
|
103
|
+
Derivative Works; within the Source form or documentation, if provided along
|
104
|
+
with the Derivative Works; or, within a display generated by the Derivative
|
105
|
+
Works, if and wherever such third-party notices normally appear. The contents of
|
106
|
+
the NOTICE file are for informational purposes only and do not modify the
|
107
|
+
License. You may add Your own attribution notices within Derivative Works that
|
108
|
+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
109
|
+
provided that such additional attribution notices cannot be construed as
|
110
|
+
modifying the License.
|
111
|
+
You may add Your own copyright statement to Your modifications and may provide
|
112
|
+
additional or different license terms and conditions for use, reproduction, or
|
113
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
114
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
115
|
+
with the conditions stated in this License.
|
116
|
+
|
117
|
+
5. Submission of Contributions.
|
118
|
+
|
119
|
+
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
120
|
+
for inclusion in the Work by You to the Licensor shall be under the terms and
|
121
|
+
conditions of this License, without any additional terms or conditions.
|
122
|
+
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
123
|
+
any separate license agreement you may have executed with Licensor regarding
|
124
|
+
such Contributions.
|
125
|
+
|
126
|
+
6. Trademarks.
|
127
|
+
|
128
|
+
This License does not grant permission to use the trade names, trademarks,
|
129
|
+
service marks, or product names of the Licensor, except as required for
|
130
|
+
reasonable and customary use in describing the origin of the Work and
|
131
|
+
reproducing the content of the NOTICE file.
|
132
|
+
|
133
|
+
7. Disclaimer of Warranty.
|
134
|
+
|
135
|
+
Unless required by applicable law or agreed to in writing, Licensor provides the
|
136
|
+
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
|
137
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
138
|
+
including, without limitation, any warranties or conditions of TITLE,
|
139
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
140
|
+
solely responsible for determining the appropriateness of using or
|
141
|
+
redistributing the Work and assume any risks associated with Your exercise of
|
142
|
+
permissions under this License.
|
143
|
+
|
144
|
+
8. Limitation of Liability.
|
145
|
+
|
146
|
+
In no event and under no legal theory, whether in tort (including negligence),
|
147
|
+
contract, or otherwise, unless required by applicable law (such as deliberate
|
148
|
+
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
149
|
+
liable to You for damages, including any direct, indirect, special, incidental,
|
150
|
+
or consequential damages of any character arising as a result of this License or
|
151
|
+
out of the use or inability to use the Work (including but not limited to
|
152
|
+
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
153
|
+
any and all other commercial damages or losses), even if such Contributor has
|
154
|
+
been advised of the possibility of such damages.
|
155
|
+
|
156
|
+
9. Accepting Warranty or Additional Liability.
|
157
|
+
|
158
|
+
While redistributing the Work or Derivative Works thereof, You may choose to
|
159
|
+
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
160
|
+
other liability obligations and/or rights consistent with this License. However,
|
161
|
+
in accepting such obligations, You may act only on Your own behalf and on Your
|
162
|
+
sole responsibility, not on behalf of any other Contributor, and only if You
|
163
|
+
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
164
|
+
incurred by, or claims asserted against, such Contributor by reason of your
|
165
|
+
accepting any such warranty or additional liability.
|
166
|
+
|
167
|
+
END OF TERMS AND CONDITIONS
|
168
|
+
|
169
|
+
APPENDIX: How to apply the Apache License to your work
|
170
|
+
|
171
|
+
To apply the Apache License to your work, attach the following boilerplate
|
172
|
+
notice, with the fields enclosed by brackets "{}" replaced with your own
|
173
|
+
identifying information. (Don't include the brackets!) The text should be
|
174
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
175
|
+
recommend that a file or class name and description of purpose be included on
|
176
|
+
the same "printed page" as the copyright notice for easier identification within
|
177
|
+
third-party archives.
|
178
|
+
|
179
|
+
Copyright 2015 newell_zlx
|
180
|
+
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
182
|
+
you may not use this file except in compliance with the License.
|
183
|
+
You may obtain a copy of the License at
|
184
|
+
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
186
|
+
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
190
|
+
See the License for the specific language governing permissions and
|
191
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -11,8 +11,20 @@ It provide One-to-one Ruby interface for Aliyun OSS Restful API. I try to keep t
|
|
11
11
|
## Document
|
12
12
|
|
13
13
|
+ [ALiyun OSS API](https://docs.aliyun.com/#/pub/oss/api-reference/overview)
|
14
|
-
+ [Ruby Document]()
|
14
|
+
+ [Ruby API Document](http://www.rubydoc.info/gems/aliyun-oss-sdk/0.0.1)
|
15
15
|
|
16
|
+
## Wiki
|
17
|
+
|
18
|
+
There are some more document here, Hope can help you!
|
19
|
+
|
20
|
+
+ [Installation](./wiki/installation.md)
|
21
|
+
+ [Get started](./wiki/get_start.md)
|
22
|
+
+ [Bucket](./wiki/bucket.md)
|
23
|
+
+ [Objects](./wiki/object.md)
|
24
|
+
+ [Multipart Upload](./wiki/multipart_upload.md)
|
25
|
+
+ [CORS](./wiki/cors.md)
|
26
|
+
+ [Lifecycle](./wiki/lifecycle.md)
|
27
|
+
+ [Error](./wiki/error.md)
|
16
28
|
|
17
29
|
## Usage
|
18
30
|
|
data/lib/aliyun/oss.rb
CHANGED
data/lib/aliyun/oss/client.rb
CHANGED
@@ -164,8 +164,13 @@ module Aliyun
|
|
164
164
|
def bucket_set_referer(referers = [], allowed_empty = false)
|
165
165
|
query = { 'referer' => true }
|
166
166
|
|
167
|
-
|
168
|
-
|
167
|
+
body = Utils.to_xml('RefererConfiguration' => {
|
168
|
+
'AllowEmptyReferer' => allowed_empty,
|
169
|
+
'RefererList' => {
|
170
|
+
'Referer' => referers
|
171
|
+
}
|
172
|
+
}
|
173
|
+
)
|
169
174
|
|
170
175
|
http.put('/', query: query, body: body, bucket: bucket)
|
171
176
|
end
|
@@ -600,7 +605,8 @@ module Aliyun
|
|
600
605
|
def bucket_list_multiparts(options = {})
|
601
606
|
accepted_keys = ['prefix', 'key-marker', 'upload-id-marker', 'max-uploads', 'delimiter', 'encoding-type']
|
602
607
|
|
603
|
-
query = Utils.hash_slice(options, *accepted_keys)
|
608
|
+
query = Utils.hash_slice(options, *accepted_keys)
|
609
|
+
.merge('uploads' => true)
|
604
610
|
|
605
611
|
http.get('/', query: query, bucket: bucket)
|
606
612
|
end
|
data/lib/aliyun/oss/http.rb
CHANGED
@@ -14,17 +14,17 @@ module Aliyun
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def put(uri, options = {})
|
17
|
-
headers =
|
17
|
+
headers = default_content_type.merge(options[:headers] || {})
|
18
18
|
request('PUT', uri, options.merge(headers: headers))
|
19
19
|
end
|
20
20
|
|
21
21
|
def post(uri, options = {})
|
22
|
-
headers =
|
22
|
+
headers = default_content_type.merge(options[:headers] || {})
|
23
23
|
request('POST', uri, options.merge(headers: headers))
|
24
24
|
end
|
25
25
|
|
26
26
|
def delete(uri, options = {})
|
27
|
-
headers =
|
27
|
+
headers = default_content_type.merge(options[:headers] || {})
|
28
28
|
request('DELETE', uri, options.merge(headers: headers))
|
29
29
|
end
|
30
30
|
|
@@ -49,11 +49,13 @@ module Aliyun
|
|
49
49
|
|
50
50
|
headers.merge!('Host' => get_host(options))
|
51
51
|
|
52
|
-
auth_key = get_auth_key(options
|
52
|
+
auth_key = get_auth_key(options
|
53
|
+
.merge(verb: verb, headers: headers, date: headers['Date']))
|
53
54
|
headers.merge!('Authorization' => auth_key)
|
54
55
|
|
55
56
|
uri = get_uri(headers['Host'], resource)
|
56
|
-
options = Utils
|
57
|
+
options = Utils
|
58
|
+
.hash_slice(options.merge(headers: headers), :query, :headers, :body)
|
57
59
|
|
58
60
|
HTTParty.__send__(verb.downcase, uri, options)
|
59
61
|
end
|
@@ -64,7 +66,8 @@ module Aliyun
|
|
64
66
|
|
65
67
|
def default_headers
|
66
68
|
{
|
67
|
-
'User-Agent' => "aliyun-oss-sdk-ruby/#{Aliyun::Oss::VERSION}
|
69
|
+
'User-Agent' => "aliyun-oss-sdk-ruby/#{Aliyun::Oss::VERSION} " \
|
70
|
+
"(#{RbConfig::CONFIG['host_os']} ruby-#{RbConfig::CONFIG['ruby_version']})",
|
68
71
|
'Date' => Time.now.utc.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
69
72
|
}
|
70
73
|
end
|
@@ -79,6 +82,10 @@ module Aliyun
|
|
79
82
|
end
|
80
83
|
end
|
81
84
|
|
85
|
+
def default_content_type
|
86
|
+
{ 'Content-Type' => 'application/x-www-form-urlencoded' }
|
87
|
+
end
|
88
|
+
|
82
89
|
def get_uri(host, resource)
|
83
90
|
"http://#{host}#{resource}"
|
84
91
|
end
|
data/lib/aliyun/oss/rule/cors.rb
CHANGED
@@ -49,7 +49,9 @@ module Aliyun
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def allowed_methods
|
52
|
-
@allowed_methods
|
52
|
+
@allowed_methods
|
53
|
+
.map(&:upcase)
|
54
|
+
.select { |method| ACCESSPTED_METHODS.include?(method.to_s) }
|
53
55
|
end
|
54
56
|
|
55
57
|
def value_present?(value)
|
@@ -27,7 +27,12 @@ module Aliyun
|
|
27
27
|
|
28
28
|
def to_hash
|
29
29
|
if valid?
|
30
|
-
{
|
30
|
+
{
|
31
|
+
'ID' => id || '',
|
32
|
+
'Prefix' => prefix,
|
33
|
+
'Status' => status,
|
34
|
+
'Expiration' => expiration
|
35
|
+
}
|
31
36
|
else
|
32
37
|
{}
|
33
38
|
end
|
data/lib/aliyun/oss/utils.rb
CHANGED
@@ -25,7 +25,8 @@ module Aliyun
|
|
25
25
|
end
|
26
26
|
|
27
27
|
# @example
|
28
|
-
#
|
28
|
+
# # { 'a' => 1, 'c' => 3 }
|
29
|
+
# Utils.hash_slice({ 'a' => 1, 'b' => 2, 'c' => 3 }, 'a', 'c')
|
29
30
|
#
|
30
31
|
# @return [Hash]
|
31
32
|
def self.hash_slice(hash, *selected_keys)
|
@@ -38,7 +39,7 @@ module Aliyun
|
|
38
39
|
#
|
39
40
|
# @return [Bin data]
|
40
41
|
def self.to_data(file_or_bin)
|
41
|
-
file_or_bin.respond_to?(:read) ? IO.binread(file_or_bin) :
|
42
|
+
file_or_bin.respond_to?(:read) ? IO.binread(file_or_bin) : file_or_bin
|
42
43
|
end
|
43
44
|
|
44
45
|
def self.to_xml(hash) # nodoc
|
data/lib/aliyun/oss/version.rb
CHANGED
data/wiki/bucket.md
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
## Bucket
|
2
|
+
|
3
|
+
Bucket is namespace in OSS, as well as management entity for high functions such as pricing, access control, logging; Bucket names are global uniqueness throughout the OSS services, and cannot be modified. Each Object stored in the OSS must contained in a Bucket. An application, such as the picture sharing website, can correspond to one or more Bucket. A user can create up to 10 Bucket, but each bucket can store unlimit objects, there is no limit to the number of storage capacity each buckte highest support 2 PB.
|
4
|
+
|
5
|
+
### Name Spec
|
6
|
+
|
7
|
+
+ only contains lowercase letters, Numbers, dash (-)
|
8
|
+
+ Must begin with lowercase letters or Numbers
|
9
|
+
+ Length must be between 3-63 bytes
|
10
|
+
|
11
|
+
|
12
|
+
### Create Bucket
|
13
|
+
|
14
|
+
require 'aliyun/oss'
|
15
|
+
|
16
|
+
access_key, secret_key = "your id", "your secret"
|
17
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
18
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host)
|
19
|
+
|
20
|
+
# create a private bucket on oss-cn-beijing
|
21
|
+
res = client.bucket_create('new-bucket', 'oss-cn-beijing', 'private')
|
22
|
+
puts res.success?, res.headers
|
23
|
+
|
24
|
+
You can specify bucket name, location and acl when create new bucket. More about this method, visit [Client#bucket_create]()
|
25
|
+
|
26
|
+
### List all buckets
|
27
|
+
|
28
|
+
To get all buckets use Client#list_buckets:
|
29
|
+
|
30
|
+
|
31
|
+
require 'aliyun/oss'
|
32
|
+
|
33
|
+
access_key, secret_key = "your id", "your secret"
|
34
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
35
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host)
|
36
|
+
|
37
|
+
res = client.list_buckets
|
38
|
+
puts res.parsed_response
|
39
|
+
|
40
|
+
|
41
|
+
### Set ACL for Bucket
|
42
|
+
|
43
|
+
With Client#bucket_set_acl you can modify the ACL for bucket:
|
44
|
+
|
45
|
+
require 'aliyun/oss'
|
46
|
+
|
47
|
+
access_key, secret_key = "your id", "your secret"
|
48
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
49
|
+
bucket = "bucket-name"
|
50
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
51
|
+
|
52
|
+
# supported value: public-read-write | public-read | private
|
53
|
+
res = client.bucket_set_acl("public-read")
|
54
|
+
puts res.parsed_response
|
55
|
+
|
56
|
+
Now, it support public-read-write | public-read | private, more detail visit: [Bucket ACL](https://docs.aliyun.com/#/pub/oss/product-documentation/acl&bucket-acl)
|
57
|
+
|
58
|
+
### Get ACL of Bucket
|
59
|
+
|
60
|
+
To get current ACL of Bucket, use Client#bucket_get_acl
|
61
|
+
|
62
|
+
|
63
|
+
require 'aliyun/oss'
|
64
|
+
|
65
|
+
access_key, secret_key = "your id", "your secret"
|
66
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
67
|
+
bucket = "bucket-name"
|
68
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
69
|
+
|
70
|
+
res = client.bucket_get_acl
|
71
|
+
puts res.parsed_response
|
72
|
+
|
73
|
+
|
74
|
+
### Get Bucket Location
|
75
|
+
|
76
|
+
Get bucket's data center location, use Client#bucket_get_location:
|
77
|
+
|
78
|
+
require 'aliyun/oss'
|
79
|
+
|
80
|
+
access_key, secret_key = "your id", "your secret"
|
81
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
82
|
+
bucket = "bucket-name"
|
83
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
84
|
+
|
85
|
+
res = client.bucket_get_location
|
86
|
+
puts res.parsed_response
|
87
|
+
|
88
|
+
More bucket information can fetch via Client#bucket_get_xxx methods. View the [Ruby Document]()
|
89
|
+
|
90
|
+
### Delete Bucket
|
91
|
+
|
92
|
+
If you donot need the bucket, delete it with Client#bucket_delete
|
93
|
+
|
94
|
+
require 'aliyun/oss'
|
95
|
+
|
96
|
+
access_key, secret_key = "your id", "your secret"
|
97
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
98
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host)
|
99
|
+
|
100
|
+
res = client.bucket_delete("deleted-bucket-name")
|
101
|
+
puts res.success?, res.headers
|
102
|
+
|
103
|
+
Note: when the bucket is not empty(existing object or parts upload via Multipart), the delete may be fail.
|
104
|
+
|
105
|
+
OK, Let's visit [Objects](./object.md)
|
106
|
+
|
data/wiki/cors.md
ADDED
File without changes
|
data/wiki/error.md
ADDED
File without changes
|
data/wiki/get_start.md
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
## Getting started
|
2
|
+
|
3
|
+
Here, you can know how to do some basic operation with Aliyun OSS SDK.
|
4
|
+
|
5
|
+
### Step-1. Init a client
|
6
|
+
|
7
|
+
Mostly API are handled by Aliyun::Oss::Client class, now Let's create a instance:
|
8
|
+
|
9
|
+
require 'aliyun/oss'
|
10
|
+
|
11
|
+
access_key, secret_key = "your id", "your secret"
|
12
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
13
|
+
bucket = "oss-sdk-dev-test"
|
14
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
15
|
+
|
16
|
+
Here, access_key/secret_key is is your access credentials, Aliyun provide three ways to fetch them, read detail at https://docs.aliyun.com/#/pub/oss/product-documentation/acl&RESTAuthentication, more about the [Aliyun::Oss::Client]()
|
17
|
+
|
18
|
+
|
19
|
+
### Step-2. Create Bucket
|
20
|
+
|
21
|
+
Buckets are global in OSS, so keep your bucket name unique with others. It can used to store many objects. Now, we create a bucket:
|
22
|
+
|
23
|
+
require 'aliyun/oss'
|
24
|
+
|
25
|
+
access_key, secret_key = "your id", "your secret"
|
26
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
27
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host)
|
28
|
+
|
29
|
+
# create a private bucket on oss-cn-beijing
|
30
|
+
res = client.bucket_create('new-bucket', 'oss-cn-beijing', 'private')
|
31
|
+
puts res.success?, res.headers
|
32
|
+
|
33
|
+
Default, most api return a [HttpartyResponse](http://www.rubydoc.info/github/jnunemaker/httparty/HTTParty/Response), you can use much methods to fetch your interesting message.
|
34
|
+
|
35
|
+
### Step-3 Upload Object
|
36
|
+
|
37
|
+
Object is the most basic unit of data in OSS, mostly it's a file. you can upload a object:
|
38
|
+
|
39
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
40
|
+
|
41
|
+
file = File.new("path/to/test.txt")
|
42
|
+
res = client.bucket_create_object("test.txt", file)
|
43
|
+
puts res.success?, res.headers
|
44
|
+
|
45
|
+
### Step-4 list all object
|
46
|
+
|
47
|
+
After you complete some upload, maybe you want to list the objects in the bucket:
|
48
|
+
|
49
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
50
|
+
|
51
|
+
res = client.bucket_list_objects()
|
52
|
+
puts res.success?, res.parsed_response
|
53
|
+
|
54
|
+
With correct parameters, you can get more flexible result.
|
55
|
+
|
56
|
+
### Step-5. Get special object
|
57
|
+
|
58
|
+
Now, you want to get a special object:
|
59
|
+
|
60
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
61
|
+
|
62
|
+
res = client.bucket_get_object("test.txt")
|
63
|
+
puts res.success?, res.headers
|
64
|
+
# save the response to your local file system
|
65
|
+
File.open("file.png", "wb") { |f| f << res.parsed_response }
|
66
|
+
|
67
|
+
Next, Visit more about [Bucket](./bucket.md)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
## Installation
|
2
|
+
|
3
|
+
It's a Ruby Gem, so you can install it like any Gem:
|
4
|
+
|
5
|
+
gem install aliyun-oss-sdk
|
6
|
+
|
7
|
+
If you use Gemfile manage your Gems, Add below to your Gemfile.
|
8
|
+
|
9
|
+
gem "aliyun-oss-sdk"
|
10
|
+
|
11
|
+
And run:
|
12
|
+
|
13
|
+
bundle install
|
14
|
+
|
15
|
+
Now, [Getting started](./get_start.md)
|
data/wiki/lifecycle.md
ADDED
File without changes
|
data/wiki/multipart.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
### Multipart Upload
|
2
|
+
|
3
|
+
require 'aliyun/oss'
|
4
|
+
|
5
|
+
access_key, secret_key = "your id", "your secret"
|
6
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
7
|
+
bucket = "bucket-name"
|
8
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
9
|
+
|
10
|
+
# Step-1 Init a Multipart Upload
|
11
|
+
client.bucket_init_multipart("Exciting-Ruby.mp4", { 'Content-Type' => 'video/mp4' })
|
12
|
+
|
13
|
+
# Step-2 Upload parts
|
14
|
+
client.bucket_multipart_upload("Exciting-Ruby.mp4", 1, "98A6524428734723BE8F81D72B5295EE", file1)
|
15
|
+
client.bucket_multipart_upload("Exciting-Ruby.mp4", 2, "98A6524428734723BE8F81D72B5295EE", file2)
|
16
|
+
|
17
|
+
# Step-3 Complete Multipart Upload
|
18
|
+
|
19
|
+
file = File.new("path/to/image.png")
|
20
|
+
res = client.bucket_create_object("image.png", file, { 'Content-Type' => 'image/png' })
|
21
|
+
puts res.success?, res.headers
|
22
|
+
|
23
|
+
res = client.bucket_create_object("hello.txt", "Hello World", { 'Content-Type' => 'text/plain' })
|
24
|
+
puts res.success?, res.headers
|
data/wiki/object.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
## Object
|
2
|
+
|
3
|
+
In Aliyun OSS, the basic data unit that user operation is the Object. A single Object maximum size varies according to the way of uploading data, Put the Object way most can't more than 5 GB, using multipart Object way to upload size must not exceed 48.8 TB. Object contains the key, meta, and data. Among them, the key is the name of the Object. Meta is user's description of the object consists of a series of name-value pairs; The data is the object data.
|
4
|
+
|
5
|
+
|
6
|
+
## Name Spec
|
7
|
+
|
8
|
+
+ Use utf-8 encoding
|
9
|
+
+ Length must be between 1 to 1023 bytes
|
10
|
+
+ Don't begin with "/" or "\" character
|
11
|
+
+ Can not contain "\r" or "\n"
|
12
|
+
|
13
|
+
|
14
|
+
## Upload Object
|
15
|
+
|
16
|
+
### Simple upload
|
17
|
+
|
18
|
+
Client#bucket_create_object support file or bin data to upload.
|
19
|
+
|
20
|
+
require 'aliyun/oss'
|
21
|
+
|
22
|
+
access_key, secret_key = "your id", "your secret"
|
23
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
24
|
+
bucket = "bucket-name"
|
25
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
26
|
+
|
27
|
+
file = File.new("path/to/image.png")
|
28
|
+
res = client.bucket_create_object("image.png", file, { 'Content-Type' => 'image/png' })
|
29
|
+
puts res.success?, res.headers
|
30
|
+
|
31
|
+
res = client.bucket_create_object("hello.txt", "Hello World", { 'Content-Type' => 'text/plain' })
|
32
|
+
puts res.success?, res.headers
|
33
|
+
|
34
|
+
|
35
|
+
The Upload limit Data to 5 GB, if large than it, use [Multipart Upload](./multipart.md).
|
36
|
+
|
37
|
+
|
38
|
+
### Create a folder
|
39
|
+
|
40
|
+
To Create a folder, it's easy, just pass key with "/" at last:
|
41
|
+
|
42
|
+
require 'aliyun/oss'
|
43
|
+
|
44
|
+
access_key, secret_key = "your id", "your secret"
|
45
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
46
|
+
bucket = "bucket-name"
|
47
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
48
|
+
|
49
|
+
res = client.bucket_create_object("images/", "")
|
50
|
+
puts res.success?, res.headers
|
51
|
+
|
52
|
+
Create simulations folder nature created a size of 0 object.Uploads and downloads, for this object can only console to end with "/" object to display the folder. So the user can use this way to implement to create simulation folder. And access to the folder can see files below the folder.
|
53
|
+
|
54
|
+
|
55
|
+
### Customize Http Header for object
|
56
|
+
|
57
|
+
OSS service allow users to customize the http headers of object. The following code set the expiration time for the Object:
|
58
|
+
|
59
|
+
require 'aliyun/oss'
|
60
|
+
|
61
|
+
access_key, secret_key = "your id", "your secret"
|
62
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
63
|
+
bucket = "bucket-name"
|
64
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
65
|
+
|
66
|
+
res = client.bucket_create_object("image.png", file, { 'Content-Type' => 'image/png', "Expires" => "Fri, 28 Feb 2012 05:38:42 GMT" })
|
67
|
+
puts res.success?, res.headers
|
68
|
+
|
69
|
+
Except Expires, also support Cache-Control, Content-Disposition, Content-Encoding, Content-MD5, more details visit: [Client#bucket_create_object]()
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aliyun-oss-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Newell Zhu
|
@@ -160,6 +160,7 @@ files:
|
|
160
160
|
- ".gitignore"
|
161
161
|
- ".travis.yml"
|
162
162
|
- Gemfile
|
163
|
+
- LICENSE
|
163
164
|
- README.md
|
164
165
|
- Rakefile
|
165
166
|
- aliyun-oss.gemspec
|
@@ -174,7 +175,14 @@ files:
|
|
174
175
|
- lib/aliyun/oss/rule/lifecycle.rb
|
175
176
|
- lib/aliyun/oss/utils.rb
|
176
177
|
- lib/aliyun/oss/version.rb
|
177
|
-
-
|
178
|
+
- wiki/bucket.md
|
179
|
+
- wiki/cors.md
|
180
|
+
- wiki/error.md
|
181
|
+
- wiki/get_start.md
|
182
|
+
- wiki/installation.md
|
183
|
+
- wiki/lifecycle.md
|
184
|
+
- wiki/multipart.md
|
185
|
+
- wiki/object.md
|
178
186
|
homepage: http://github.com/aliyun/ruby-oss-sdk
|
179
187
|
licenses: []
|
180
188
|
metadata: {}
|