aliyun-oss-sdk 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -1
- data/Gemfile +2 -1
- data/README.md +46 -20
- data/aliyun-oss.gemspec +4 -4
- data/lib/aliyun/oss/client.rb +3 -3
- data/lib/aliyun/oss/http.rb +2 -2
- data/lib/aliyun/oss/utils.rb +1 -1
- data/lib/aliyun/oss/version.rb +1 -1
- data/wiki/error.md +58 -0
- data/wiki/multipart.md +113 -12
- data/wiki/object.md +168 -2
- metadata +7 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48824060a243cb4767d975c02b036ccedf0dba0a
|
4
|
+
data.tar.gz: 0cdbddaf0f33abac43e4c5e5e05346df08773307
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a38cd11c82084a0d7f61d0d96b8f4e69dd3cad0e37dc0e724561dd343065da244166e5752221c85c477d181082705ff68245df3750a5d87ed3ca5cbb49564e35
|
7
|
+
data.tar.gz: ddb90c90e27a46a468c4fb7dbdff4683a6bd0f3f3d52626c71369704b227ad5d921e95f716a7cac3e345520b1b6fcb435f681cbec8eee9caa4a26c777359218b
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,30 +1,30 @@
|
|
1
1
|
# Aliyun OSS SDK
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Build Status](https://travis-ci.org/zlx/aliyun-oss-sdk.svg)](https://travis-ci.org/zlx/aliyun-oss-sdk)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/zlx/aliyun-oss-sdk.png)](https://codeclimate.com/github/zlx/aliyun-oss-sdk)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/zlx/aliyun-oss-sdk/badge.svg?branch=master&service=github)](https://coveralls.io/github/zlx/aliyun-oss-sdk?branch=master)
|
4
6
|
|
5
7
|
-----
|
6
8
|
|
7
9
|
|
8
|
-
It provide One-to-one Ruby interface for Aliyun OSS Restful API. I try to keep things natural and reasonable, but there are always some places are leaky, welcome to give me advice and modification.
|
10
|
+
It provide One-to-one Ruby interface for Aliyun OSS Restful API. I try to keep things natural and reasonable, but there are always some places are leaky, welcome to give me advice and modification. Enjoy it!
|
9
11
|
|
10
12
|
|
11
|
-
## Document
|
12
13
|
|
13
|
-
|
14
|
-
+ [Ruby API Document](http://www.rubydoc.info/gems/aliyun-oss-sdk/0.0.1)
|
14
|
+
## Installation
|
15
15
|
|
16
|
-
|
16
|
+
It's a Ruby Gem, so you can install it like any Gem:
|
17
17
|
|
18
|
-
|
18
|
+
gem install aliyun-oss-sdk
|
19
|
+
|
20
|
+
If you use Gemfile manage your Gems, Add below to your Gemfile.
|
21
|
+
|
22
|
+
gem "aliyun-oss-sdk"
|
23
|
+
|
24
|
+
And run:
|
25
|
+
|
26
|
+
bundle install
|
19
27
|
|
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)
|
28
28
|
|
29
29
|
## Usage
|
30
30
|
|
@@ -32,21 +32,25 @@ There are some more document here, Hope can help you!
|
|
32
32
|
|
33
33
|
require 'aliyun/oss'
|
34
34
|
|
35
|
-
# ACCESS_KEY/SECRET_KEY is your access credentials
|
36
|
-
# host: your bucket's data center host, eg: oss-cn-hangzhou.aliyuncs.com
|
35
|
+
# ACCESS_KEY/SECRET_KEY is your access credentials
|
36
|
+
# host: your bucket's data center host, eg: oss-cn-hangzhou.aliyuncs.com
|
37
|
+
# Details: https://docs.aliyun.com/#/pub/oss/product-documentation/domain-region#menu2
|
37
38
|
# bucket: your bucket name
|
38
39
|
|
39
40
|
client = Aliyun::OSS::Client.new('ACCESS_KEY', 'SECRET_KEY', host: 'oss-cn-hangzhou.aliyuncs.com', bucket: 'oss-sdk-dev-hangzhou')
|
40
41
|
|
41
|
-
# Get all objects in this bucket
|
42
|
-
# use prefix,marker,delimiter, max-keys to filter results
|
43
|
-
client.bucket_list_objects()
|
44
42
|
|
45
43
|
# Upload objects
|
46
44
|
client.bucket_create_object('image.png', File.new('path/to/image.png'), { 'Content-Type' => 'image/png' })
|
47
45
|
|
48
46
|
# Get Object
|
49
47
|
client.bucket_get_object('image.png')
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
# Get all objects in this bucket
|
52
|
+
# use prefix,marker,delimiter, max-keys to filter results
|
53
|
+
client.bucket_list_objects()
|
50
54
|
|
51
55
|
|
52
56
|
### Share your files
|
@@ -197,6 +201,28 @@ With Post Form, we need Post Policy to restrict permissions, here we provide two
|
|
197
201
|
|
198
202
|
|
199
203
|
|
204
|
+
## Document
|
205
|
+
|
206
|
+
Here is original Restful API, It has the most detailed and authoritative explanation for every API.
|
207
|
+
|
208
|
+
+ [https://docs.aliyun.com/#/pub/oss/api-reference/overview](https://docs.aliyun.com/#/pub/oss/api-reference/overview)
|
209
|
+
|
210
|
+
Here is thr Ruby Document for this Library, use to find more usage for methods.
|
211
|
+
|
212
|
+
+ [Ruby API Document](http://www.rubydoc.info/gems/aliyun-oss-sdk/0.0.1)
|
213
|
+
|
214
|
+
|
215
|
+
Here are some more guides for help you. Welcome to advice.
|
216
|
+
|
217
|
+
+ [Installation](./wiki/installation.md)
|
218
|
+
+ [Get started](./wiki/get_start.md)
|
219
|
+
+ [Bucket](./wiki/bucket.md)
|
220
|
+
+ [Objects](./wiki/object.md)
|
221
|
+
+ [Multipart Upload](./wiki/multipart.md)
|
222
|
+
+ [Error](./wiki/error.md)
|
223
|
+
|
224
|
+
|
225
|
+
|
200
226
|
## Authors && Contributors
|
201
227
|
|
202
228
|
- [Newell Zhu](https://github.com/zlx_star)
|
data/aliyun-oss.gemspec
CHANGED
@@ -21,12 +21,12 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_dependency 'httparty'
|
22
22
|
spec.add_dependency 'gyoku'
|
23
23
|
|
24
|
-
spec.add_development_dependency 'bundler'
|
25
|
-
spec.add_development_dependency 'rake'
|
24
|
+
spec.add_development_dependency 'bundler'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
26
|
spec.add_development_dependency 'minitest'
|
27
27
|
spec.add_development_dependency 'mocha'
|
28
|
-
spec.add_development_dependency 'pry-byebug'
|
28
|
+
#spec.add_development_dependency 'pry-byebug'
|
29
29
|
spec.add_development_dependency 'webmock'
|
30
30
|
spec.add_development_dependency 'timecop'
|
31
|
-
spec.add_development_dependency 'simplecov'
|
31
|
+
#spec.add_development_dependency 'simplecov'
|
32
32
|
end
|
data/lib/aliyun/oss/client.rb
CHANGED
@@ -18,7 +18,7 @@ module Aliyun
|
|
18
18
|
# @option options [String] :host host for bucket's data center
|
19
19
|
# @option options [String] :bucket Bucket name
|
20
20
|
#
|
21
|
-
# @return [
|
21
|
+
# @return [Response]
|
22
22
|
def initialize(access_key, secret_key, options = {})
|
23
23
|
@access_key = access_key
|
24
24
|
@secret_key = secret_key
|
@@ -35,7 +35,7 @@ module Aliyun
|
|
35
35
|
# @option options [String] :marker Bucket name should after marker in alphabetical order
|
36
36
|
# @option options [Integer] :max-keys (100) Limit number of buckets, the maxinum should <= 1000
|
37
37
|
#
|
38
|
-
# @return [
|
38
|
+
# @return [Response]
|
39
39
|
def list_buckets(options = {})
|
40
40
|
query = Utils.hash_slice(options, 'prefix', 'marker', 'max-keys')
|
41
41
|
http.get('/', query: query)
|
@@ -52,7 +52,7 @@ module Aliyun
|
|
52
52
|
# @option options [String] :delimiter Used to group objects with delimiter
|
53
53
|
# @option options [String] :encoding-type Encoding type used for unsupported character
|
54
54
|
#
|
55
|
-
# @return [
|
55
|
+
# @return [Response]
|
56
56
|
def bucket_list_objects(options = {})
|
57
57
|
accepted_keys = ['prefix', 'marker', 'max-keys', 'delimiter', 'encoding-type']
|
58
58
|
query = Utils.hash_slice(options, *accepted_keys)
|
data/lib/aliyun/oss/http.rb
CHANGED
@@ -53,11 +53,11 @@ module Aliyun
|
|
53
53
|
.merge(verb: verb, headers: headers, date: headers['Date']))
|
54
54
|
headers.merge!('Authorization' => auth_key)
|
55
55
|
|
56
|
-
|
56
|
+
path = get_uri(headers['Host'], resource)
|
57
57
|
options = Utils
|
58
58
|
.hash_slice(options.merge(headers: headers), :query, :headers, :body)
|
59
59
|
|
60
|
-
HTTParty.__send__(verb.downcase,
|
60
|
+
HTTParty.__send__(verb.downcase, path, options)
|
61
61
|
end
|
62
62
|
|
63
63
|
def get_auth_key(options)
|
data/lib/aliyun/oss/utils.rb
CHANGED
data/lib/aliyun/oss/version.rb
CHANGED
data/wiki/error.md
CHANGED
@@ -0,0 +1,58 @@
|
|
1
|
+
## Error
|
2
|
+
|
3
|
+
### Handle Error
|
4
|
+
|
5
|
+
If a error occurs when visit the OSS, the OSS will be return a error code and error message, making it easy for users to locate problems, and make the appropriate treatment. For code not 2XX, you can get information:
|
6
|
+
|
7
|
+
require 'aliyun/oss'
|
8
|
+
|
9
|
+
client = Aliyun::OSS::Client.new('ACCESS_KEY', 'SECRET_KEY', host: 'oss-cn-hangzhou.aliyuncs.com', bucket: 'oss-sdk-dev-hangzhou')
|
10
|
+
|
11
|
+
res = client.bucket_create("invalid_bucket_name")
|
12
|
+
unless res.success?
|
13
|
+
puts "Code: #{res.code}"
|
14
|
+
puts "Message: #{res.message}"
|
15
|
+
puts "Request id: #{res.parsed_response['Error']['RequestId']}"
|
16
|
+
end
|
17
|
+
|
18
|
+
Here,
|
19
|
+
|
20
|
+
+ Code: the error code
|
21
|
+
+ Message: the error message
|
22
|
+
+ requestId: It's the UUID to uniquely identifies this request; When you can't solve the problem, can the RequestId to request help from the OSS development engineer.
|
23
|
+
|
24
|
+
|
25
|
+
# Error Code
|
26
|
+
|
27
|
+
| code | summary |
|
28
|
+
|---|---|
|
29
|
+
|AccessDenied |Access denied |
|
30
|
+
|BucketAlreadyExists | Bucket Already Exist|
|
31
|
+
|BucketNotEmpty |Bucket Not Empty|
|
32
|
+
|EntityTooLarge | Entry Too Large|
|
33
|
+
|EntityTooSmall | Entry Too Small|
|
34
|
+
|FileGroupTooLarge |File Group Too Large|
|
35
|
+
|FilePartNotExist |File Part Not Exist|
|
36
|
+
|FilePartStale | File Part Expired|
|
37
|
+
|InvalidArgument |Invalid Argument|
|
38
|
+
|InvalidAccessKeyId | Access Key ID Not Exist|
|
39
|
+
|InvalidBucketName | The specified bucket is not valid.|
|
40
|
+
|InvalidDigest | Invalid Digest |
|
41
|
+
|InvalidObjectName |Invalid Object Name|
|
42
|
+
|InvalidPart | Invalid Part|
|
43
|
+
|InvalidPartOrder |Invalid Part Order|
|
44
|
+
|InvalidTargetBucketForLogging |Invalid Target Bucket For Logging|
|
45
|
+
|InternalError |Internal Error|
|
46
|
+
|MalformedXML |Malformed XML|
|
47
|
+
|MethodNotAllowed |Method Not Allowed|
|
48
|
+
|MissingArgument |Missing Argument|
|
49
|
+
|MissingContentLength |Missing Content Length|
|
50
|
+
|NoSuchBucket |No Such Bucket|
|
51
|
+
|NoSuchKey |No Such Key|
|
52
|
+
|NoSuchUpload |Multipart Upload ID Not Exist|
|
53
|
+
|NotImplemented |Not Implemented|
|
54
|
+
|PreconditionFailed |Precondition Failed|
|
55
|
+
|RequestTimeTooSkewed |Request Time Large Than 15 minutes|
|
56
|
+
|RequestTimeout |Request Timeout|
|
57
|
+
|SignatureDoesNotMatch |Signature Does Not Match|
|
58
|
+
|TooManyBuckets |Too Many Buckets|
|
data/wiki/multipart.md
CHANGED
@@ -1,6 +1,22 @@
|
|
1
|
-
|
1
|
+
## Multipart Upload
|
2
2
|
|
3
|
-
|
3
|
+
Besides simple upload via put, OSS provide another way to upload large file -- Multipart Upload, Here we list some normal application scenarios:
|
4
|
+
|
5
|
+
+ To support breakpoint upload
|
6
|
+
+ Upload file large than 100 MB
|
7
|
+
+ Network is bad, and the connection between the OSS server often disconnected
|
8
|
+
+ Upload a file before, unable to determine the size of the uploaded files
|
9
|
+
|
10
|
+
|
11
|
+
Now, Let's start party!
|
12
|
+
|
13
|
+
|
14
|
+
### Initialize
|
15
|
+
|
16
|
+
Before start a Multipart Upload, we need first initialize a event:
|
17
|
+
|
18
|
+
|
19
|
+
require 'aliyun/oss'
|
4
20
|
|
5
21
|
access_key, secret_key = "your id", "your secret"
|
6
22
|
host = "oss-cn-hangzhou.aliyuncs.com"
|
@@ -8,17 +24,102 @@
|
|
8
24
|
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
9
25
|
|
10
26
|
# Step-1 Init a Multipart Upload
|
11
|
-
client.bucket_init_multipart("Exciting-Ruby.mp4", { 'Content-Type' => 'video/mp4' })
|
27
|
+
res = client.bucket_init_multipart("Exciting-Ruby.mp4", { 'Content-Type' => 'video/mp4' })
|
28
|
+
if res.success?
|
29
|
+
puts "Upload ID: #{res.parsed_response['InitiateMultipartUploadResult']['UploadId']}"
|
30
|
+
else
|
31
|
+
puts res.code, res.message
|
32
|
+
end
|
12
33
|
|
13
|
-
|
14
|
-
|
15
|
-
|
34
|
+
Upload ID is the UUID for the Multipart Upload Event, store it for use later.
|
35
|
+
|
36
|
+
### Upload Part from local
|
37
|
+
|
38
|
+
require 'aliyun/oss'
|
39
|
+
|
40
|
+
access_key, secret_key = "your id", "your secret"
|
41
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
42
|
+
bucket = "bucket-name"
|
43
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
16
44
|
|
17
|
-
|
45
|
+
res = client.bucket_multipart_upload("Exciting-Ruby.mp4", 1, "Upload ID", file_or_bin)
|
46
|
+
|
47
|
+
if res.success?
|
48
|
+
puts "etag: #{res.headers['etag']}"
|
49
|
+
else
|
50
|
+
puts res.code, res.message
|
51
|
+
end
|
52
|
+
|
53
|
+
Store the etag, it will used for complete a Multipart Upload.
|
54
|
+
|
55
|
+
It can used to upload part to a object. Please note:
|
56
|
+
|
57
|
+
+ Multipart Upload requirements every parts greater than 100 KB except last one
|
58
|
+
+ In order to ensure that data safe when network transmission, strongly recommend to include meta: content-md5, after receiving the data, OSS using the md5 value to prove the validity of the upload data, if they are inconsistent returns InvalidDigest.
|
59
|
+
+ The Part number range is 1~10000. If beyond this range, the OSS will return InvalidArgument.
|
60
|
+
+ If you upload from the same file, be careful for the upload position
|
61
|
+
|
62
|
+
### Complete Multipart Upload
|
63
|
+
|
64
|
+
require 'aliyun/oss'
|
65
|
+
|
66
|
+
access_key, secret_key = "your id", "your secret"
|
67
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
68
|
+
bucket = "bucket-name"
|
69
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
70
|
+
|
71
|
+
part1 = Aliyun::Oss::Multipart::Part.new({ number: 1, etag: 'etag1' })
|
72
|
+
part2 = Aliyun::Oss::Multipart::Part.new({ number: 2, etag: 'etag2' })
|
73
|
+
part3 = Aliyun::Oss::Multipart::Part.new({ number: 3, etag: 'etag3' })
|
74
|
+
res = client.bucket_complete_multipart("Exciting-Ruby.mp4", "Upload ID", [part1, part2, part3])
|
75
|
+
|
76
|
+
|
77
|
+
Here, we create Aliyun::Oss::Multipart::Part to build your part, use Part#valid? to valid the object.
|
78
|
+
|
79
|
+
### Abort Multipart Upload
|
80
|
+
|
81
|
+
If some Problem occurs, you may want to abort a Multipart Upload:
|
82
|
+
|
83
|
+
require 'aliyun/oss'
|
84
|
+
|
85
|
+
access_key, secret_key = "your id", "your secret"
|
86
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
87
|
+
bucket = "bucket-name"
|
88
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
89
|
+
|
90
|
+
res = client.bucket_abort_multipart("Exciting-Ruby.mp4", "Upload ID")
|
91
|
+
|
92
|
+
After abort a multipart, all uploaded parts will be destroyed, But Note: If some others are upload parts to this object when your abort, they may be missing, so invoke a few times if you have access in concurrent.
|
93
|
+
|
94
|
+
### List Multipart Upload
|
95
|
+
|
96
|
+
To get all Multipart Upload in this Bucket:
|
97
|
+
|
98
|
+
require 'aliyun/oss'
|
99
|
+
|
100
|
+
access_key, secret_key = "your id", "your secret"
|
101
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
102
|
+
bucket = "bucket-name"
|
103
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
104
|
+
|
105
|
+
res = client.bucket_list_multiparts
|
106
|
+
puts res.success?, res.parsed_response
|
107
|
+
|
108
|
+
Same with all other list method, it support prefix, delimiter, marker to get flexible results.
|
109
|
+
|
110
|
+
|
111
|
+
### List Uploaded Parts
|
112
|
+
|
113
|
+
Sometimes, you want to know which parts are uploaded.
|
114
|
+
|
115
|
+
require 'aliyun/oss'
|
116
|
+
|
117
|
+
access_key, secret_key = "your id", "your secret"
|
118
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
119
|
+
bucket = "bucket-name"
|
120
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
18
121
|
|
19
|
-
|
20
|
-
res
|
21
|
-
puts res.success?, res.headers
|
122
|
+
res = client.bucket_list_parts("Upload ID")
|
123
|
+
puts res.success?, res.parsed_response
|
22
124
|
|
23
|
-
|
24
|
-
puts res.success?, res.headers
|
125
|
+
|
data/wiki/object.md
CHANGED
@@ -63,12 +63,178 @@ OSS service allow users to customize the http headers of object. The following c
|
|
63
63
|
bucket = "bucket-name"
|
64
64
|
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
65
65
|
|
66
|
+
file = File.new("path/to/image.png")
|
66
67
|
res = client.bucket_create_object("image.png", file, { 'Content-Type' => 'image/png', "Expires" => "Fri, 28 Feb 2012 05:38:42 GMT" })
|
67
68
|
puts res.success?, res.headers
|
68
69
|
|
69
|
-
Except Expires, also support Cache-Control, Content-Disposition, Content-Encoding, Content-MD5, more details visit: [Client#bucket_create_object]()
|
70
|
+
Except Expires, also support Cache-Control, Content-Disposition, Content-Encoding, Content-MD5, more details visit: [Client#bucket_create_object]().
|
71
|
+
|
72
|
+
|
73
|
+
### Set User Meta
|
74
|
+
|
75
|
+
OSS Support meta information for object.
|
76
|
+
|
77
|
+
require 'aliyun/oss'
|
78
|
+
|
79
|
+
access_key, secret_key = "your id", "your secret"
|
80
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
81
|
+
bucket = "bucket-name"
|
82
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
83
|
+
|
84
|
+
file = File.new("path/to/image.png")
|
85
|
+
res = client.bucket_create_object("image.png", file, { 'Content-Type' => 'image/png', 'x-oss-meta-user' => 'baymax' })
|
86
|
+
puts res.success?, res.headers
|
87
|
+
|
88
|
+
|
89
|
+
user meta is information with "x-oss-meta" stored in headers, the maxinum limit is 2KB.
|
90
|
+
|
91
|
+
Note: the user meta key is case-insensitive, but value is case-sensitive.
|
92
|
+
|
93
|
+
|
94
|
+
### Append Upload
|
95
|
+
|
96
|
+
OSS Allow users to append data to a object, but only for appendable object, Objects created with Append Upload is Appendable object, Upload via simple upload is Normal object:
|
97
|
+
|
98
|
+
|
99
|
+
require 'aliyun/oss'
|
100
|
+
|
101
|
+
access_key, secret_key = "your id", "your secret"
|
102
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
103
|
+
bucket = "bucket-name"
|
104
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
105
|
+
|
106
|
+
# Step-1 create a appendable object
|
107
|
+
position = 0
|
108
|
+
res = client.bucket_append_object("secret.zip", "init information", position)
|
109
|
+
|
110
|
+
# Step-2 get next append position
|
111
|
+
position = res.headers['x-oss-next-append-position']
|
112
|
+
|
113
|
+
# Step-3 append upload
|
114
|
+
res = client.bucket_append_object("secret.zip", "append information", position)
|
115
|
+
puts res.success?, res.headers
|
116
|
+
|
117
|
+
Users upload with Append mode, the important is to set position correctly. When a user creates an Appendable Object, additional position to 0. When the Appendable Object for additional content, additional location as the Object of the current length. There are two ways to get the Object length: one is through return after the upload additional content. Another is fetch by head object(Client#bucket_get_meta_object). the next position is store with header: x-oss-next-append.
|
118
|
+
|
119
|
+
Note: Only when create the appendable object can set object meta. Later if you need to change the object meta, can use copy object interface(Client#bucket_copy_object) -- source and destination for the same Object.
|
120
|
+
|
121
|
+
## List objects in Bucket
|
122
|
+
|
123
|
+
|
124
|
+
### List Objects
|
125
|
+
|
126
|
+
require 'aliyun/oss'
|
127
|
+
|
128
|
+
access_key, secret_key = "your id", "your secret"
|
129
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
130
|
+
bucket = "bucket-name"
|
131
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
132
|
+
|
133
|
+
res = client.bucket_list_objects
|
134
|
+
puts res.success?, res.parsed_response
|
135
|
+
|
136
|
+
|
137
|
+
### More Parameters
|
138
|
+
|
139
|
+
the method support many Parameters to get flexible results:
|
140
|
+
|
141
|
+
require 'aliyun/oss'
|
142
|
+
|
143
|
+
access_key, secret_key = "your id", "your secret"
|
144
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
145
|
+
bucket = "bucket-name"
|
146
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
147
|
+
|
148
|
+
# list objects with prefix: pic and end with "/"
|
149
|
+
res = client.bucket_list_objects(prefix: 'pic', delimiter: '/')
|
150
|
+
puts res.success?, res.parsed_response
|
151
|
+
|
152
|
+
It list results with prefix: pic and end with "/", for example: "pic-people/". More about the Paramters, visit: [Client#bucket_list_objects]()
|
153
|
+
|
154
|
+
### Get Object
|
155
|
+
|
156
|
+
require 'aliyun/oss'
|
157
|
+
|
158
|
+
access_key, secret_key = "your id", "your secret"
|
159
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
160
|
+
bucket = "bucket-name"
|
161
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
162
|
+
|
163
|
+
res = client.bucket_get_object('image.png')
|
164
|
+
puts res.success?, res.parsed_response
|
165
|
+
|
166
|
+
It Support much Parameters, Range, If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match. With Range, we can get data from a object, it's useful for download partly and so on.
|
70
167
|
|
168
|
+
|
169
|
+
### Get Meta Object
|
170
|
+
|
171
|
+
To get meta information of a object, use Client#get_meta_object:
|
172
|
+
|
173
|
+
require 'aliyun/oss'
|
174
|
+
|
175
|
+
access_key, secret_key = "your id", "your secret"
|
176
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
177
|
+
bucket = "bucket-name"
|
178
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
179
|
+
|
180
|
+
res = client.bucket_get_meta_object('image.png')
|
181
|
+
puts res.success?, res.headers
|
71
182
|
|
183
|
+
### Delete Object
|
72
184
|
|
185
|
+
require 'aliyun/oss'
|
186
|
+
|
187
|
+
access_key, secret_key = "your id", "your secret"
|
188
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
189
|
+
bucket = "bucket-name"
|
190
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
191
|
+
|
192
|
+
# Delete one object
|
193
|
+
res = client.bucket_delete_object('image.png')
|
194
|
+
puts res.success?, res.headers
|
195
|
+
|
196
|
+
|
197
|
+
# Delete many objects at once
|
198
|
+
# the second Paramter used to control the response information. Quiet or Verbose
|
199
|
+
res = client.bucket_delete_objects(['image1.png', 'image2.png'], true)
|
200
|
+
puts res.success?, res.headers
|
73
201
|
|
74
|
-
|
202
|
+
|
203
|
+
### Copy Object
|
204
|
+
|
205
|
+
|
206
|
+
With Client#bucket_copy_object, we can copy objects from some bucket to others.
|
207
|
+
|
208
|
+
require 'aliyun/oss'
|
209
|
+
|
210
|
+
access_key, secret_key = "your id", "your secret"
|
211
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
212
|
+
bucket = "bucket-name"
|
213
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
214
|
+
|
215
|
+
res = client.bucket_copy_object('new_image.png', 'origin-bucket-name', 'origin.png')
|
216
|
+
puts res.success?, res.headers
|
217
|
+
|
218
|
+
Note: the origin bucket and target bucket must locate at same region.
|
219
|
+
|
220
|
+
Now, it allow to modify User meta information.
|
221
|
+
|
222
|
+
|
223
|
+
### Modify Object Meta
|
224
|
+
|
225
|
+
With Copy object, specify the source object and target object to the same one, we can implement modify user meta information.
|
226
|
+
|
227
|
+
require 'aliyun/oss'
|
228
|
+
|
229
|
+
access_key, secret_key = "your id", "your secret"
|
230
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
231
|
+
bucket = "bucket-name"
|
232
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
233
|
+
|
234
|
+
headers = { "Content-Type" => "image/japeg" }
|
235
|
+
res = client.bucket_copy_object('image.png', 'bucket-name', 'image.png', headers)
|
236
|
+
puts res.success?, res.headers
|
237
|
+
|
238
|
+
|
239
|
+
|
240
|
+
That's it, Here we visit [Multipart Upload](./multipart.md)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Newell Zhu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -40,34 +40,6 @@ dependencies:
|
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '1.10'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '1.10'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rake
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '10.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '10.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: minitest
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
72
44
|
requirements:
|
73
45
|
- - ">="
|
@@ -81,7 +53,7 @@ dependencies:
|
|
81
53
|
- !ruby/object:Gem::Version
|
82
54
|
version: '0'
|
83
55
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
56
|
+
name: rake
|
85
57
|
requirement: !ruby/object:Gem::Requirement
|
86
58
|
requirements:
|
87
59
|
- - ">="
|
@@ -95,7 +67,7 @@ dependencies:
|
|
95
67
|
- !ruby/object:Gem::Version
|
96
68
|
version: '0'
|
97
69
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
70
|
+
name: minitest
|
99
71
|
requirement: !ruby/object:Gem::Requirement
|
100
72
|
requirements:
|
101
73
|
- - ">="
|
@@ -109,7 +81,7 @@ dependencies:
|
|
109
81
|
- !ruby/object:Gem::Version
|
110
82
|
version: '0'
|
111
83
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
84
|
+
name: mocha
|
113
85
|
requirement: !ruby/object:Gem::Requirement
|
114
86
|
requirements:
|
115
87
|
- - ">="
|
@@ -123,7 +95,7 @@ dependencies:
|
|
123
95
|
- !ruby/object:Gem::Version
|
124
96
|
version: '0'
|
125
97
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
98
|
+
name: webmock
|
127
99
|
requirement: !ruby/object:Gem::Requirement
|
128
100
|
requirements:
|
129
101
|
- - ">="
|
@@ -137,7 +109,7 @@ dependencies:
|
|
137
109
|
- !ruby/object:Gem::Version
|
138
110
|
version: '0'
|
139
111
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
112
|
+
name: timecop
|
141
113
|
requirement: !ruby/object:Gem::Requirement
|
142
114
|
requirements:
|
143
115
|
- - ">="
|