aliyun-sdk 0.4.1 → 0.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +25 -0
- data/README.md +174 -172
- data/examples/aliyun/oss/bucket.rb +0 -0
- data/examples/aliyun/oss/callback.rb +0 -0
- data/examples/aliyun/oss/object.rb +0 -0
- data/examples/aliyun/oss/resumable_download.rb +0 -0
- data/examples/aliyun/oss/resumable_upload.rb +0 -0
- data/examples/aliyun/oss/streaming.rb +0 -0
- data/examples/aliyun/oss/using_sts.rb +0 -0
- data/examples/aliyun/sts/assume_role.rb +0 -0
- data/ext/crcx/crc64_ecma.c +270 -0
- data/ext/crcx/crcx.c +45 -0
- data/ext/crcx/crcx.h +8 -0
- data/ext/crcx/extconf.rb +3 -0
- data/lib/aliyun/common.rb +0 -0
- data/lib/aliyun/common/exception.rb +0 -0
- data/lib/aliyun/common/logging.rb +6 -1
- data/lib/aliyun/common/struct.rb +0 -0
- data/lib/aliyun/oss.rb +1 -0
- data/lib/aliyun/oss/bucket.rb +41 -33
- data/lib/aliyun/oss/client.rb +10 -2
- data/lib/aliyun/oss/config.rb +4 -1
- data/lib/aliyun/oss/download.rb +2 -2
- data/lib/aliyun/oss/exception.rb +6 -0
- data/lib/aliyun/oss/http.rb +32 -48
- data/lib/aliyun/oss/iterator.rb +0 -0
- data/lib/aliyun/oss/multipart.rb +1 -1
- data/lib/aliyun/oss/object.rb +0 -0
- data/lib/aliyun/oss/protocol.rb +68 -8
- data/lib/aliyun/oss/struct.rb +2 -2
- data/lib/aliyun/oss/upload.rb +0 -0
- data/lib/aliyun/oss/util.rb +25 -1
- data/lib/aliyun/sts.rb +0 -0
- data/lib/aliyun/sts/client.rb +1 -1
- data/lib/aliyun/sts/config.rb +0 -0
- data/lib/aliyun/sts/exception.rb +0 -0
- data/lib/aliyun/sts/protocol.rb +3 -3
- data/lib/aliyun/sts/struct.rb +0 -0
- data/lib/aliyun/sts/util.rb +0 -0
- data/lib/aliyun/version.rb +1 -1
- data/spec/aliyun/oss/bucket_spec.rb +194 -18
- data/spec/aliyun/oss/client/bucket_spec.rb +342 -30
- data/spec/aliyun/oss/client/client_spec.rb +26 -1
- data/spec/aliyun/oss/client/resumable_download_spec.rb +0 -0
- data/spec/aliyun/oss/client/resumable_upload_spec.rb +0 -0
- data/spec/aliyun/oss/http_spec.rb +26 -0
- data/spec/aliyun/oss/multipart_spec.rb +53 -8
- data/spec/aliyun/oss/object_spec.rb +256 -10
- data/spec/aliyun/oss/service_spec.rb +0 -0
- data/spec/aliyun/oss/util_spec.rb +101 -0
- data/spec/aliyun/sts/client_spec.rb +0 -0
- data/spec/aliyun/sts/util_spec.rb +0 -0
- data/tests/config.rb +2 -0
- data/tests/helper.rb +15 -0
- data/tests/test_content_encoding.rb +0 -0
- data/tests/test_content_type.rb +0 -0
- data/tests/test_crc_check.rb +184 -0
- data/tests/test_custom_headers.rb +14 -6
- data/tests/test_encoding.rb +0 -0
- data/tests/test_large_file.rb +0 -0
- data/tests/test_multipart.rb +0 -0
- data/tests/test_object_acl.rb +0 -0
- data/tests/test_object_key.rb +18 -0
- data/tests/test_object_url.rb +20 -0
- data/tests/test_resumable.rb +0 -0
- metadata +33 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5bc5cc4acd9d6e01955fd76f3b15e38d73a352f457c181bb9de469af4f30c4f3
|
4
|
+
data.tar.gz: 2ec82c787847ed16ac7172cec823756f8752700a8366048127487d3257a2af32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4af5842f0231aa8d5fd3c301e70418f895a5b9e5a36e254a184a4715b70389119a78c931e823ca0df039fde1020b32e82d598becf867b6416b39ecdf904635b
|
7
|
+
data.tar.gz: 94edfce3d26df7ee399e62b56e48f22c055df2ab967affd22d40f4145e48f27bdc8ada7a16916464330287569a58eb0cbd17d8c5dbca73ce2fd31b081d96644c
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,30 @@
|
|
1
1
|
## Change Log
|
2
2
|
|
3
|
+
### v0.7.2 / 2020-06-05
|
4
|
+
|
5
|
+
- add env parameter to descide whether output log file
|
6
|
+
|
7
|
+
### v0.7.1 / 2019-11-16
|
8
|
+
|
9
|
+
- add the validity check of bucket name
|
10
|
+
- add parameters argument for buclet.object_url api
|
11
|
+
- fix http.get_request_url function bug
|
12
|
+
- fix warning constant ::Fixnum is deprecated
|
13
|
+
- support rest-client 2.1.0
|
14
|
+
|
15
|
+
### v0.7.0 / 2018-06-05
|
16
|
+
|
17
|
+
- deps: upgrade nokogiri to > 1.6 and ruby version >= 2.0
|
18
|
+
|
19
|
+
### v0.6.0 / 2017-07-23
|
20
|
+
|
21
|
+
- deps: upgrade rest-client to 2.x
|
22
|
+
|
23
|
+
### v0.5.0 / 2016-11-08
|
24
|
+
|
25
|
+
- feat: add crc check for uploading(enabled by default) and downloading(disabled by default)
|
26
|
+
- bug: fix file open mode for multipart
|
27
|
+
|
3
28
|
### v0.4.1 / 2016-07-19
|
4
29
|
|
5
30
|
- Support signature object url with STS
|
data/README.md
CHANGED
@@ -1,75 +1,73 @@
|
|
1
|
-
#
|
1
|
+
# Alibaba Cloud OSS SDK for Ruby
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/aliyun-sdk.svg)](https://badge.fury.io/rb/aliyun-sdk)
|
4
4
|
[![Build Status](https://travis-ci.org/aliyun/aliyun-oss-ruby-sdk.svg?branch=master)](https://travis-ci.org/aliyun/aliyun-oss-ruby-sdk?branch=master)
|
5
5
|
[![Coverage Status](https://coveralls.io/repos/aliyun/aliyun-oss-ruby-sdk/badge.svg?branch=master&service=github)](https://coveralls.io/github/aliyun/aliyun-oss-ruby-sdk?branch=master)
|
6
6
|
|
7
|
-
|
7
|
+
## [README of Chinese](https://github.com/aliyun/aliyun-oss-ruby-sdk/blob/master/README-CN.md)
|
8
8
|
|
9
|
-
|
10
|
-
RESTful API的Ruby客户端程序。了解OSS的的更多信息请访问OSS官网:
|
11
|
-
http://www.aliyun.com/product/oss
|
9
|
+
## About
|
12
10
|
|
13
|
-
|
11
|
+
Alibaba Cloud OSS SDK for Ruby is a Ruby client program for convenient access to Alibaba Cloud OSS (Object Storage Service)
|
12
|
+
RESTful APIs. For more information about OSS, visit [the OSS official website]( http://www.aliyun.com/product/oss).
|
14
13
|
|
15
|
-
|
16
|
-
- 支持Ruby运行环境的Windows/Linux/OS X
|
14
|
+
## Run environment
|
17
15
|
|
18
|
-
|
16
|
+
- Ruby ***2.0*** or above. For Ruby 1.9, please use v0.5.0.
|
17
|
+
- *Windows*, *Linux* or *OS X* system that supports Ruby.
|
19
18
|
|
20
|
-
|
19
|
+
To learn how to install Ruby, refer to: [ruby-lang](https://www.ruby-lang.org/en/documentation/installation/).
|
21
20
|
|
22
|
-
|
21
|
+
## Quick start
|
23
22
|
|
24
|
-
|
25
|
-
开通OSS服务。开通服务之后请在“管理控制台”中查看您的AccessKeyId和
|
26
|
-
AccessKeySecret,在使用Aliyun OSS SDK时需要提供您的这两个信息。
|
23
|
+
### Activate an OSS account
|
27
24
|
|
28
|
-
|
25
|
+
Log onto [the official website](http://www.aliyun.com/product/oss) and click *Activate Now*. Follow the prompts
|
26
|
+
to activate OSS. After the service is activated, go to *Console* to view your `AccessKeyId` and
|
27
|
+
`AccessKeySecret`. These two information items are required when you use Alibaba Cloud OSS SDK.
|
28
|
+
|
29
|
+
### Install Alibaba Cloud OSS SDK for Ruby
|
29
30
|
|
30
31
|
gem install aliyun-sdk
|
31
32
|
|
32
|
-
|
33
|
+
Include the following in your project or 'irb' command:
|
33
34
|
|
34
35
|
require 'aliyun/oss'
|
35
36
|
|
36
|
-
|
37
|
+
**Note:**
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
- Some gems on which the SDK depends are local extensions, and you need to install ruby-dev to compile locally
|
40
|
+
extended gems after you install Ruby.
|
41
|
+
- The environment for running the SDK-dependent gem (nokogiri) for processing XML must have the zlib library.
|
41
42
|
|
42
|
-
|
43
|
+
The following method is used to install the preceding dependencies taking *Ubuntu* as an example:
|
43
44
|
|
44
45
|
sudo apt-get install ruby-dev
|
45
46
|
sudo apt-get install zlib1g-dev
|
46
47
|
|
47
|
-
|
48
|
+
The practices for other systems are similar.
|
48
49
|
|
49
|
-
###
|
50
|
+
### Create a client
|
50
51
|
|
51
52
|
client = Aliyun::OSS::Client.new(
|
52
53
|
:endpoint => 'endpoint',
|
53
54
|
:access_key_id => 'access_key_id',
|
54
55
|
:access_key_secret => 'access_key_secret')
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
[节点列表][region-list]
|
57
|
+
In specific, the `endpoint` is the OSS service address. The address may vary based on different regions for the node. For example,
|
58
|
+
the address for a Hangzhou node is: `http://oss-cn-hangzhou.aliyuncs.com`. For addresses for other nodes, see: [Node List][region-list].
|
59
59
|
|
60
|
-
`access_key_id
|
61
|
-
台”上面可以查看。**请妥善保管您的AccessKeySecret,泄露之后可能影响您的
|
62
|
-
数据安全**
|
60
|
+
The `access_key_id` and `access_key_secret` are credentials for your service. You can view them in `Console` on the official website. **Please keep your AccessKeySecret safe. Disclosing the AccessKeySecret may compromise your data security**.
|
63
61
|
|
64
|
-
####
|
62
|
+
#### Use a bound domain as the endpoint
|
65
63
|
|
66
|
-
OSS
|
67
|
-
|
68
|
-
|
69
|
-
|
64
|
+
OSS supports binding a custom domain name and allows you to direct your domain name to the OSS service address
|
65
|
+
(CNAME) of Alibaba Cloud. In this way, you don't need to change the resource path in your app when migrating your data to the OSS. The bound domain name
|
66
|
+
points to a bucket in the OSS. The domain name binding operation can only be carried out in the OSS console. For more information about
|
67
|
+
binding a custom domain name, visit the official website: [Binding Custom Domain Names in OSS][custom-domain].
|
70
68
|
|
71
|
-
|
72
|
-
|
69
|
+
After you have bound a custom domain name, you can use the standard OSS service address as the specified endpoint of the OSS,
|
70
|
+
or use the bound domain name:
|
73
71
|
|
74
72
|
client = Aliyun::OSS::Client.new(
|
75
73
|
:endpoint => 'http://img.my-domain.com',
|
@@ -77,19 +75,19 @@ OSS支持自定义域名绑定,允许用户将自己的域名指向阿里云OS
|
|
77
75
|
:access_key_secret => 'access_key_secret',
|
78
76
|
:cname => true)
|
79
77
|
|
80
|
-
|
78
|
+
**Note:**
|
81
79
|
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
80
|
+
- You must set the `cname` to ***true*** when initializing the client.
|
81
|
+
- The custom domain name is bound to a bucket of the OSS, so the client created in this method does not support
|
82
|
+
List_buckets operations.
|
83
|
+
- You still need to specify the bucket name during the {Aliyun::OSS::Client#get_bucket} operation and the bucket name should be the same as that
|
84
|
+
bound to the domain name.
|
87
85
|
|
88
|
-
####
|
86
|
+
#### Create a client using STS
|
89
87
|
|
90
|
-
OSS
|
91
|
-
|
92
|
-
|
88
|
+
OSS supports access via STS. For more information about STS, refer to [Alibaba Cloud STS][aliyun-sts].
|
89
|
+
Before using STS, you must apply for a temporary token from the STS.
|
90
|
+
Alibaba Cloud Ruby SDK contains the STS SDK, and you only need to `require 'aliyun/sts'` for usage:
|
93
91
|
|
94
92
|
require 'aliyun/sts'
|
95
93
|
sts = Aliyun::STS::Client.new(
|
@@ -104,71 +102,70 @@ aliyun-sdk中包含了STS的SDK,使用时只需要`require 'aliyun/sts'`即可
|
|
104
102
|
:access_key_secret => token.access_key_secret,
|
105
103
|
:sts_token => token.security_token)
|
106
104
|
|
107
|
-
|
108
|
-
带Policy的token,细节请参考[API文档][sdk-api]。
|
105
|
+
**Note:** the `:sts_token` parameter must be specified for using STS. You can also apply for a token with a policy through `STS::Client`, for details, refer to [API Documentation][sdk-api].
|
109
106
|
|
110
|
-
###
|
107
|
+
### List all the current buckets
|
111
108
|
|
112
109
|
buckets = client.list_buckets
|
113
110
|
buckets.each{ |b| puts b.name }
|
114
111
|
|
115
|
-
`list_buckets
|
116
|
-
|
112
|
+
The `list_buckets` command returns an iterator for you to get the information of each bucket in order. Bucket
|
113
|
+
For the object structure, see {Aliyun::OSS::Bucket} in the API documentation.
|
117
114
|
|
118
|
-
###
|
115
|
+
### Create a bucket
|
119
116
|
|
120
117
|
bucket = client.create_bucket('my-bucket')
|
121
118
|
|
122
|
-
###
|
119
|
+
### List all the objects in a bucket
|
123
120
|
|
124
121
|
bucket = client.get_bucket('my-bucket')
|
125
122
|
objects = bucket.list_objects
|
126
123
|
objects.each{ |o| puts o.key }
|
127
124
|
|
128
|
-
`list_objects
|
129
|
-
|
125
|
+
The `list_objects` command returns an iterator for you to get the information of each object in order. Object
|
126
|
+
For the object structure, see {Aliyun::OSS::Object} in the API documentation.
|
130
127
|
|
131
|
-
###
|
128
|
+
### Create an object in the bucket
|
132
129
|
|
133
130
|
bucket.put_object(object_key){ |stream| stream << 'hello world' }
|
134
131
|
|
135
|
-
|
132
|
+
You can also create an object by uploading a local file:
|
136
133
|
|
137
134
|
bucket.put_object(object_key, :file => local_file)
|
138
135
|
|
139
|
-
###
|
136
|
+
### Download an object from the bucket
|
140
137
|
|
141
138
|
bucket.get_object(object_key){ |content| puts content }
|
142
139
|
|
143
|
-
|
140
|
+
You can also download the object to a local file:
|
144
141
|
|
145
142
|
bucket.get_object(object_key, :file => local_file)
|
146
143
|
|
147
|
-
###
|
144
|
+
### Copy an object
|
148
145
|
|
149
146
|
bucket.copy_object(from_key, to_key)
|
150
147
|
|
151
|
-
###
|
148
|
+
### Identify whether an object exists
|
152
149
|
|
153
150
|
bucket.object_exists?(object_key)
|
154
151
|
|
155
|
-
|
152
|
+
For more operations on buckets, refer to {Aliyun::OSS::Bucket} in the API documentation.
|
156
153
|
|
157
|
-
##
|
154
|
+
## Simulate the directory structure
|
158
155
|
|
159
|
-
OSS
|
160
|
-
|
161
|
-
|
156
|
+
OSS is a storage service for objects and does not support the directory structure. All objects are flatly structured. But
|
157
|
+
you can simulate the directory structure by setting the object key in the format "foo/bar/file".
|
158
|
+
Suppose there are several objects as follows:
|
162
159
|
|
163
160
|
foo/x
|
164
161
|
foo/bar/f1
|
165
162
|
foo/bar/dir/file
|
166
163
|
foo/hello/file
|
167
164
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
165
|
+
Listing all the objects under the "foo/" directory means to perform the *list_objects* operation with "foo/" as the prefix.
|
166
|
+
But this method will also list all the objects under "foo/bar/". That's why we need the delimiter parameter.
|
167
|
+
This parameter means to stop processing at the first delimiter after the prefix. The key during the process acts as
|
168
|
+
the common prefix of objects, objects with the prefix will be included in the *list_objects* result.
|
172
169
|
|
173
170
|
objs = bucket.list_objects(:prefix => 'foo/', :delimiter => '/')
|
174
171
|
objs.each do |i|
|
@@ -183,17 +180,17 @@ Object的common prefix,包含在`list_objects`的结果中。
|
|
183
180
|
common prefix: foo/bar/
|
184
181
|
common prefix: foo/hello/
|
185
182
|
|
186
|
-
Common prefix
|
187
|
-
|
183
|
+
Common prefixes free you from traversing all the objects (the number of objects may be huge) to determine the prefix,
|
184
|
+
and is quite helpful for simulating the directory structure.
|
188
185
|
|
189
|
-
##
|
186
|
+
## Upload callback
|
190
187
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
188
|
+
You can specify a *callback* for `put_object` and `resumable_upload` so that after the file
|
189
|
+
is successfully uploaded to the OSS, the OSS will initiate an *HTTP POST* request to the server address you provided
|
190
|
+
to notify you that the corresponding event has occurred. You can perform desired actions after receiving the notification,
|
191
|
+
such as updating the database and making statistics. For more details about upload callback, refer to [OSS Upload Callback][oss-callback].
|
195
192
|
|
196
|
-
|
193
|
+
The example below demonstrates how to use the upload callback:
|
197
194
|
|
198
195
|
callback = Aliyun::OSS::Callback.new(
|
199
196
|
url: 'http://10.101.168.94:1234/callback',
|
@@ -207,31 +204,31 @@ Common prefix让用户不需要遍历所有的object(可能数量巨大)而
|
|
207
204
|
puts "Callback failed: #{e.message}"
|
208
205
|
end
|
209
206
|
|
210
|
-
|
207
|
+
**Note:**
|
211
208
|
|
212
|
-
|
213
|
-
|
214
|
-
`CallbackError
|
215
|
-
|
216
|
-
|
209
|
+
- The callback URL **must not** contain the query string which must be specified in the `:query` parameter.
|
210
|
+
- In the event that the file is successfully uploaded but callback execution fails, the client will throw
|
211
|
+
`CallbackError`. To ignore the error, you need to explicitly catch the exception.
|
212
|
+
- For detailed examples, refer to [callback.rb](examples/aliyun/oss/callback.rb).
|
213
|
+
- For servers that support callback, refer to [callback_server.rb](rails/aliyun_oss_callback_server.rb).
|
217
214
|
|
218
|
-
##
|
215
|
+
## Resumable upload/download
|
219
216
|
|
220
|
-
OSS
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
217
|
+
OSS supports the storage of large objects. If the upload/download task of a large object is interrupted (due to network transient disconnections, program crashes, or machine power-off),
|
218
|
+
the re-upload/re-download is taxing on system resources. The OSS supports
|
219
|
+
multipart upload/download to divide a large object into multiple parts for upload/download. Alibaba Cloud OSS SDK
|
220
|
+
provides the resumable upload/download feature based on this principle. If an interruption occurs, you can resume the upload/download task
|
221
|
+
beginning with the interrupted part. ***Resumable upload/download is recommended for objects
|
222
|
+
larger than 100MB***.
|
226
223
|
|
227
|
-
###
|
224
|
+
### Resumable upload
|
228
225
|
|
229
226
|
bucket.resumable_upload(object_key, local_file, :cpt_file => cpt_file)
|
230
227
|
|
231
|
-
|
232
|
-
|
233
|
-
`local_file.cpt
|
234
|
-
|
228
|
+
In specific, `:cpt_file` specifies the location of the checkpoint object which stores the intermediate state of the upload.
|
229
|
+
If no object is specified, the SDK will generate a
|
230
|
+
`local_file.cpt` in the directory of the `local_file`. After the upload interruption, you only need to provide the same cpt object for the upload task to resume from
|
231
|
+
the interrupted part. The typical upload code is:
|
235
232
|
|
236
233
|
retry_times = 5
|
237
234
|
retry_times.times do
|
@@ -242,21 +239,21 @@ Multipart的功能,可以在上传/下载时将大文件进行分片传输。A
|
|
242
239
|
end
|
243
240
|
end
|
244
241
|
|
245
|
-
|
242
|
+
**Notes:**
|
246
243
|
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
244
|
+
- The SDK records the upload intermediate states in the cpt object. Therefore, ensure that you have
|
245
|
+
write permission on the cpt object.
|
246
|
+
- The cpt object records the intermediate state information of the upload and has a self-checking function. You cannot edit the object.
|
247
|
+
Upload will fail if the cpt object is corrupted. When the upload is completed, the checkpoint file will be deleted.
|
251
248
|
|
252
|
-
###
|
249
|
+
### Resumable download
|
253
250
|
|
254
251
|
bucket.resumable_download(object_key, local_file, :cpt_file => cpt_file)
|
255
252
|
|
256
|
-
|
257
|
-
|
258
|
-
`local_file.cpt
|
259
|
-
|
253
|
+
In specific, `:cpt_file` specifies the location of the checkpoint object which stores the intermediate state of the download.
|
254
|
+
If no object is specified, the SDK will generate a
|
255
|
+
`local_file.cpt` in the directory of the `local_file`. After the download interruption, you only need to provide the same cpt object for the download task to resume from
|
256
|
+
the interrupted part. The typical download code is:
|
260
257
|
|
261
258
|
retry_times = 5
|
262
259
|
retry_times.times do
|
@@ -267,55 +264,55 @@ Multipart的功能,可以在上传/下载时将大文件进行分片传输。A
|
|
267
264
|
end
|
268
265
|
end
|
269
266
|
|
270
|
-
|
267
|
+
**Notes:**
|
271
268
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
269
|
+
- During the download process, a temporary object of `local_file.part.N` will be generated in the directory of the `local_file`
|
270
|
+
for each part downloaded. When the download is completed, the objects will be deleted.
|
271
|
+
You cannot edit or delete the part objects, otherwise the download will not proceed.
|
272
|
+
- The SDK records the download intermediate states in the cpt object; therefore, ensure that you have
|
273
|
+
write permission on the cpt object.
|
274
|
+
- The cpt object records the intermediate state information of the download and has a self-checking function. You cannot edit the object.
|
275
|
+
Download will fail if the cpt object is corrupted. When the download is completed, the `checkpoint` object will be deleted.
|
279
276
|
|
280
277
|
|
281
|
-
|
278
|
+
# Appendable object
|
282
279
|
|
283
|
-
|
280
|
+
Objects in Alibaba Cloud OSS can be divided into two types: Normal and Appendable.
|
284
281
|
|
285
|
-
-
|
286
|
-
|
287
|
-
-
|
288
|
-
`append_object
|
289
|
-
-
|
290
|
-
-
|
282
|
+
- A normal object functions as a whole for every upload. If an object already exists,
|
283
|
+
the later uploaded object will overwrite the previous object with the same key.
|
284
|
+
- An appendable object is created through `append_object` for the first time. The later uploaded
|
285
|
+
object through `append_object` will not overwrite the previous one, but will append content to the end of the object.
|
286
|
+
- You cannot append content to a normal object.
|
287
|
+
- You cannot copy an appendable object.
|
291
288
|
|
292
|
-
###
|
289
|
+
### Create an appendable object
|
293
290
|
|
294
291
|
bucket.append_object(object_key, 0){ |stream| stream << "hello world" }
|
295
292
|
|
296
|
-
|
297
|
-
|
293
|
+
The second parameter indicates the position to append the content. This parameter is ***0*** for the first append to the object. In later
|
294
|
+
append operations, the value of this parameter is the length of the object before the append.
|
298
295
|
|
299
|
-
|
296
|
+
Of course, you can also read the appended content from the object:
|
300
297
|
|
301
298
|
bucket.append_object(object_key, 0, :file => local_file)
|
302
299
|
|
303
|
-
###
|
300
|
+
### Append content to the object
|
304
301
|
|
305
302
|
pos = bucket.get_object(object_key).size
|
306
303
|
next_pos = bucket.append_object(object_key, pos, :file => local_file)
|
307
304
|
|
308
|
-
|
309
|
-
|
305
|
+
During the first append, you can use {Aliyun::OSS::Bucket#get_object} to get the object length.
|
306
|
+
For later append operations, you can refer to the response of {Aliyun::OSS::Bucket#append_object} to determine the length value for next append.
|
310
307
|
|
311
|
-
|
308
|
+
***Note:*** Concurrent `append_object` and `next_pos` operations do not always produce correct results.
|
312
309
|
|
313
|
-
## Object meta
|
310
|
+
## Object meta information
|
314
311
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
312
|
+
Besides the object content, the OSS also allows you to set some *meta information* for the object during object uploading.
|
313
|
+
The meta information is a key-value pair to identify the specific attributes of the object. The
|
314
|
+
meta information will be stored together with the object and returned to users in `get_object` and `get_object_meta`
|
315
|
+
operations.
|
319
316
|
|
320
317
|
bucket.put_object(object_key, :file => local_file,
|
321
318
|
:metas => {
|
@@ -325,36 +322,36 @@ Multipart的功能,可以在上传/下载时将大文件进行分片传输。A
|
|
325
322
|
obj = bucket.get_object(object_key, :file => localfile)
|
326
323
|
puts obj.metas
|
327
324
|
|
328
|
-
|
325
|
+
**Note:**
|
329
326
|
|
330
|
-
|
331
|
-
|
332
|
-
|
327
|
+
- The key and value of the meta information can only be simple ASCII non-newline characters and the total size must not exceed ***8KB***.
|
328
|
+
- In the copy object operation, the meta information of the source object will be copied by default. If you don't want this, explicitly set the
|
329
|
+
`:meta_directive` to {Aliyun::OSS::MetaDirective::REPLACE}.
|
333
330
|
|
334
|
-
##
|
331
|
+
## Permission control
|
335
332
|
|
336
|
-
OSS
|
337
|
-
|
333
|
+
OSS allows you to set access permissions for buckets and objects respectively, so that you can conveniently control
|
334
|
+
external access to your resources. A bucket is enabled with three types of access permissions:
|
338
335
|
|
339
|
-
- public-read-write
|
340
|
-
- public-read
|
341
|
-
- private
|
336
|
+
- public-read-write: Anonymous users are allowed to create/retrieve/delete objects in the bucket.
|
337
|
+
- public-read: Anonymous users are allowed to retrieve objects in the bucket.
|
338
|
+
- private: Anonymous users are not allowed to access the bucket. Signature is required for all accesses.
|
342
339
|
|
343
|
-
|
344
|
-
|
340
|
+
When a bucket is created, the private permission applies by default. You can use 'bucket.acl=' to set
|
341
|
+
the ACL of the bucket.
|
345
342
|
|
346
343
|
bucket.acl = Aliyun::OSS::ACL::PUBLIC_READ
|
347
344
|
puts bucket.acl # public-read
|
348
345
|
|
349
|
-
|
346
|
+
An object is enabled with four types of access permissions:
|
350
347
|
|
351
|
-
- default
|
352
|
-
- public-read-write
|
353
|
-
- public-read
|
354
|
-
- private
|
348
|
+
- default: The object inherits the access permissions of the bucket it belongs to, that is, the access permission of the object is the same as that of the bucket where the object is stored.
|
349
|
+
- public-read-write: Anonymous users are allowed to read/write the object.
|
350
|
+
- public-read: Anonymous users are allowed to read the object.
|
351
|
+
- private: Anonymous users are not allowed to access the object. Signature is required for all accesses.
|
355
352
|
|
356
|
-
|
357
|
-
|
353
|
+
When an object is created, the default permission applies by default. You can use
|
354
|
+
'bucket.set_object_acl' to configure the ACL of the object.
|
358
355
|
|
359
356
|
acl = bucket.get_object_acl(object_key)
|
360
357
|
puts acl # default
|
@@ -362,28 +359,28 @@ Bucket的权限。
|
|
362
359
|
acl = bucket.get_object_acl(object_key)
|
363
360
|
puts acl # public-read
|
364
361
|
|
365
|
-
|
362
|
+
**Notes:**
|
366
363
|
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
364
|
+
- If an object is configured with an ACL policy, the object ACL takes priority during permission authentication
|
365
|
+
when the object is accessed. The bucket ACL will be ignored.
|
366
|
+
- If anonymous access is allowed (public-read or public-read-write is configured for the object), you
|
367
|
+
can directly access the object using a browser. For example,
|
371
368
|
|
372
369
|
http://bucket-name.oss-cn-hangzhou.aliyuncs.com/object.jpg
|
373
370
|
|
374
|
-
|
371
|
+
- A bucket or an object with the public permission can be accessed by an anonymous client which is created with the following code:
|
375
372
|
|
376
|
-
#
|
377
|
-
#
|
373
|
+
# If access_key_id and access_key_secret are not specified, an anonymous client will be created. The client can only access
|
374
|
+
# the buckets and objects with the public permission.
|
378
375
|
client = Client.new(:endpoint => 'oss-cn-hangzhou.aliyuncs.com')
|
379
376
|
bucket = client.get_bucket('public-bucket')
|
380
377
|
obj = bucket.get_object('public-object', :file => local_file)
|
381
378
|
|
382
|
-
##
|
379
|
+
## Run examples
|
383
380
|
|
384
|
-
SDK
|
385
|
-
|
386
|
-
`~/.oss.yml
|
381
|
+
Some example projects are provided in the examples/ directory of the SDK to demonstrate the SDK features. You can run the examples
|
382
|
+
after some configuration. The permission information and the bucket information required by the examples are available in the
|
383
|
+
`~/.oss.yml` configuration file under the *HOME* directory. The information should include the following fields (**Note the space after the colon**):
|
387
384
|
|
388
385
|
endpoint: oss-cn-hangzhou.aliyuncs.com
|
389
386
|
cname: false
|
@@ -391,11 +388,11 @@ SDK的examples/目录下有一些展示SDK功能的示例程序,用户稍加
|
|
391
388
|
access_key_secret: <ACCESS KEY SECRET>
|
392
389
|
bucket: <BUCKET NAME>
|
393
390
|
|
394
|
-
|
391
|
+
You need to create (if not in existence) or modify the content and run the example project:
|
395
392
|
|
396
393
|
ruby examples/aliyun/oss/bucket.rb
|
397
394
|
|
398
|
-
##
|
395
|
+
## Run test
|
399
396
|
|
400
397
|
```bash
|
401
398
|
bundle exec rake spec
|
@@ -408,12 +405,16 @@ export RUBY_SDK_OSS_BUCKET=bucket-name
|
|
408
405
|
bundle exec rake test
|
409
406
|
```
|
410
407
|
|
411
|
-
##
|
408
|
+
## License
|
409
|
+
|
410
|
+
- MIT
|
412
411
|
|
413
|
-
|
412
|
+
## More
|
414
413
|
|
415
|
-
|
416
|
-
|
414
|
+
For more documentation, see:
|
415
|
+
|
416
|
+
- Alibaba Cloud OSS Ruby SDK [documentation](https://help.aliyun.com/document_detail/oss/sdk/ruby-sdk/install.html).
|
417
|
+
- Alibaba Cloud OSS [documentation](http://help.aliyun.com/product/8314910_oss.html).
|
417
418
|
|
418
419
|
|
419
420
|
[region-list]: https://help.aliyun.com/document_detail/oss/user_guide/endpoint_region.html
|
@@ -421,3 +422,4 @@ bundle exec rake test
|
|
421
422
|
[aliyun-sts]: https://help.aliyun.com/document_detail/ram/intro/concepts.html
|
422
423
|
[sdk-api]: http://www.rubydoc.info/gems/aliyun-sdk/
|
423
424
|
[oss-callback]: https://help.aliyun.com/document_detail/oss/user_guide/upload_object/upload_callback.html
|
425
|
+
|