aliyun-oss-sdk 0.0.3 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +17 -0
- data/Gemfile +1 -0
- data/README.md +12 -10
- data/Rakefile +10 -0
- data/aliyun-oss.gemspec +2 -2
- data/lib/aliyun/oss.rb +4 -11
- data/lib/aliyun/oss/authorization.rb +59 -27
- data/lib/aliyun/oss/client.rb +137 -62
- data/lib/aliyun/oss/client/bucket_multiparts.rb +43 -0
- data/lib/aliyun/oss/client/bucket_objects.rb +111 -0
- data/lib/aliyun/oss/client/buckets.rb +50 -0
- data/lib/aliyun/oss/client/clients.rb +54 -0
- data/lib/aliyun/oss/error.rb +43 -0
- data/lib/aliyun/oss/http.rb +65 -23
- data/lib/aliyun/oss/struct.rb +26 -0
- data/lib/aliyun/oss/struct/bucket.rb +252 -0
- data/lib/aliyun/oss/struct/cors.rb +65 -0
- data/lib/aliyun/oss/struct/lifecycle.rb +73 -0
- data/lib/aliyun/oss/struct/logging.rb +33 -0
- data/lib/aliyun/oss/struct/multipart.rb +101 -0
- data/lib/aliyun/oss/struct/object.rb +71 -0
- data/lib/aliyun/oss/struct/part.rb +48 -0
- data/lib/aliyun/oss/struct/referer.rb +21 -0
- data/lib/aliyun/oss/struct/website.rb +13 -0
- data/lib/aliyun/oss/utils.rb +41 -1
- data/lib/aliyun/oss/version.rb +1 -1
- data/lib/aliyun/oss/xml_generator.rb +174 -0
- data/todo.md +5 -0
- data/wiki/bucket.md +20 -20
- data/wiki/cors.md +59 -0
- data/wiki/error.md +42 -31
- data/wiki/get_start.md +24 -7
- data/wiki/installation.md +2 -2
- data/wiki/lifecycle.md +75 -0
- data/wiki/multipart.md +7 -5
- data/wiki/object.md +16 -12
- metadata +48 -6
- data/lib/aliyun/oss/multipart/part.rb +0 -32
- data/lib/aliyun/oss/rule/cors.rb +0 -63
- data/lib/aliyun/oss/rule/lifecycle.rb +0 -61
data/wiki/cors.md
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
## CORS
|
2
|
+
|
3
|
+
CORS allow web application visit resources not belongs it's domain. OSS provide interface to help developer control the premissions.
|
4
|
+
|
5
|
+
|
6
|
+
### Set CORS
|
7
|
+
|
8
|
+
|
9
|
+
With Client#bucket_enable_cors, you can set cors easily:
|
10
|
+
|
11
|
+
require 'aliyun/oss'
|
12
|
+
|
13
|
+
access_key, secret_key = "your id", "your secret"
|
14
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
15
|
+
bucket = "bucket-name"
|
16
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
17
|
+
|
18
|
+
rule = Aliyun::Oss::Struct::Cors.new(allowed_methods: ['get'], allowed_origins: ['*'])
|
19
|
+
res = client.bucket_enable_cors([rule])
|
20
|
+
puts res.success?, res.headers
|
21
|
+
|
22
|
+
More about the rules, visit [OSS API](https://docs.aliyun.com/#/pub/oss/api-reference/cors&PutBucketcors) and [Struct::Cors]()
|
23
|
+
|
24
|
+
|
25
|
+
### Get CORS Rules
|
26
|
+
|
27
|
+
To get current cors rules, you can use Client#bucket_get_cors:
|
28
|
+
|
29
|
+
|
30
|
+
require 'aliyun/oss'
|
31
|
+
|
32
|
+
access_key, secret_key = "your id", "your secret"
|
33
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
34
|
+
bucket = "bucket-name"
|
35
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
36
|
+
|
37
|
+
res = client.bucket_get_cors
|
38
|
+
puts res.success?, res.parsed_response
|
39
|
+
|
40
|
+
|
41
|
+
### Disable CORS
|
42
|
+
|
43
|
+
If you want to diable CORS, just like below:
|
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
|
+
# create a private bucket on oss-cn-beijing
|
53
|
+
res = client.bucket_disable_cors
|
54
|
+
puts res.success?, res.headers
|
55
|
+
|
56
|
+
Note: disable CORS will remove all existing CORS Rules.
|
57
|
+
|
58
|
+
|
59
|
+
Now, Let's go to next section: [LifeCycle](./lifecycle.md)
|
data/wiki/error.md
CHANGED
@@ -24,35 +24,46 @@ Here,
|
|
24
24
|
|
25
25
|
# Error Code
|
26
26
|
|
27
|
-
| code | summary |
|
27
|
+
| code | summary | HTTP Status|
|
28
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
29
|
+
|AccessDenied |Access denied | 403|
|
30
|
+
|BucketAlreadyExists | Bucket Already Exist| 409|
|
31
|
+
|BucketNotEmpty |Bucket Not Empty| 409|
|
32
|
+
|EntityTooLarge | Entry Too Large| 400|
|
33
|
+
|EntityTooSmall | Entry Too Small| 400|
|
34
|
+
|FileGroupTooLarge |File Group Too Large| 400|
|
35
|
+
|InvalidLinkName | Object Link Same With Object| 400|
|
36
|
+
|LinkPartNotExist | Object Not Exist| 400|
|
37
|
+
|ObjectLinkTooLarge | Object Too Much | 400|
|
38
|
+
|FieldItemTooLong | Field Too Large| 400|
|
39
|
+
|FilePartInterity | File Part Already Changed| 400|
|
40
|
+
|FilePartNotExist |File Part Not Exist| 400|
|
41
|
+
|FilePartStale | File Part Expired| 400|
|
42
|
+
|IncorrectNumberOfFilesInPOSTRequest| File Count Invalid| 400|
|
43
|
+
|InvalidArgument |Invalid Argument| 400|
|
44
|
+
|InvalidAccessKeyId | Access Key ID Not Exist| 403|
|
45
|
+
|InvalidBucketName | The specified bucket is not valid.| 400|
|
46
|
+
|InvalidDigest | Invalid Digest | 400|
|
47
|
+
|InvalidEncryptionAlgorithmError | Specified Encoding-Type Error | 400|
|
48
|
+
|InvalidObjectName |Invalid Object Name| 400
|
49
|
+
|InvalidPart | Invalid Part| 400|
|
50
|
+
|InvalidPartOrder |Invalid Part Order| 400|
|
51
|
+
|InvalidPolicyDocument | Invalid Policy| 400|
|
52
|
+
|InvalidTargetBucketForLogging |Invalid Target Bucket For Logging| 400|
|
53
|
+
|InternalError |Internal Error| 500|
|
54
|
+
|MalformedXML | XML Invalid| 400|
|
55
|
+
|MalformedPOSTRequest | Requested XML Invalid | 400|
|
56
|
+
|MaxPOSTPreDataLengthExceededError | Body except file Too Large | 400|
|
57
|
+
|MethodNotAllowed |Method Not Allowed| 405|
|
58
|
+
|MissingArgument |Missing Argument| 411|
|
59
|
+
|MissingContentLength |Missing Content Length| 411|
|
60
|
+
|NoSuchBucket |No Such Bucket| 404|
|
61
|
+
|NoSuchKey |No Such Key| 404|
|
62
|
+
|NoSuchUpload |Multipart Upload ID Not Exist| 404|
|
63
|
+
|NotImplemented |Not Implemented| 501|
|
64
|
+
|PreconditionFailed |Precondition Failed| 412|
|
65
|
+
|RequestTimeTooSkewed |Request Time Large Than 15 minutes| 403|
|
66
|
+
|RequestTimeout |Request Timeout| 400|
|
67
|
+
|RequestIsNotMultiPartContent | Content-Type Invalid| 400|
|
68
|
+
|SignatureDoesNotMatch |Signature Does Not Match|403|
|
69
|
+
|TooManyBuckets |Too Many Buckets| 400|
|
data/wiki/get_start.md
CHANGED
@@ -2,23 +2,24 @@
|
|
2
2
|
|
3
3
|
Here, you can know how to do some basic operation with Aliyun OSS SDK.
|
4
4
|
|
5
|
+
|
5
6
|
### Step-1. Init a client
|
6
7
|
|
7
|
-
Mostly API are handled by Aliyun::Oss::Client class,
|
8
|
+
Mostly OSS API are handled by [Aliyun::Oss::Client](http://www.rubydoc.info/gems/aliyun-oss-sdk/Aliyun/Oss/Client) class, Let's create a instance first:
|
8
9
|
|
9
10
|
require 'aliyun/oss'
|
10
11
|
|
11
12
|
access_key, secret_key = "your id", "your secret"
|
12
13
|
host = "oss-cn-hangzhou.aliyuncs.com"
|
13
|
-
bucket = "
|
14
|
+
bucket = "bucket-name"
|
14
15
|
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
15
16
|
|
16
|
-
Here, access_key/secret_key is is your access credentials, Aliyun provide three ways to
|
17
|
+
Here, access_key/secret_key is is your access credentials, Aliyun provide three ways to get access credentials, get more information [here](https://docs.aliyun.com/#/pub/oss/product-documentation/acl&RESTAuthentication).
|
17
18
|
|
18
19
|
|
19
20
|
### Step-2. Create Bucket
|
20
21
|
|
21
|
-
Buckets are global in OSS, so
|
22
|
+
Buckets are global object in OSS, so find a uniqueness name for your bucket, Or it fail when create. It can used to store objects. Now, we create a bucket:
|
22
23
|
|
23
24
|
require 'aliyun/oss'
|
24
25
|
|
@@ -30,33 +31,49 @@ Buckets are global in OSS, so keep your bucket name unique with others. It can u
|
|
30
31
|
res = client.bucket_create('new-bucket', 'oss-cn-beijing', 'private')
|
31
32
|
puts res.success?, res.headers
|
32
33
|
|
33
|
-
|
34
|
+
In our library, most instance methods of Client return [HttpartyResponse](http://www.rubydoc.info/github/jnunemaker/httparty/HTTParty/Response), you can use rich methods to fetch your interesting message.
|
35
|
+
|
34
36
|
|
35
37
|
### Step-3 Upload Object
|
36
38
|
|
37
|
-
Object is the most basic unit of data in OSS,
|
39
|
+
Object is the most basic unit of data in OSS, you can simple imagine it's just a file. here, we upload a object to OSS:
|
38
40
|
|
41
|
+
require 'aliyun/oss'
|
42
|
+
|
43
|
+
access_key, secret_key = "your id", "your secret"
|
44
|
+
host, bucket = "oss-cn-hangzhou.aliyuncs.com", "bucket-name"
|
39
45
|
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
40
46
|
|
41
47
|
file = File.new("path/to/test.txt")
|
42
48
|
res = client.bucket_create_object("test.txt", file)
|
43
49
|
puts res.success?, res.headers
|
44
50
|
|
51
|
+
|
45
52
|
### Step-4 list all object
|
46
53
|
|
47
54
|
After you complete some upload, maybe you want to list the objects in the bucket:
|
48
55
|
|
56
|
+
|
57
|
+
require 'aliyun/oss'
|
58
|
+
|
59
|
+
access_key, secret_key = "your id", "your secret"
|
60
|
+
host, bucket = "oss-cn-hangzhou.aliyuncs.com", "bucket-name"
|
49
61
|
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
50
62
|
|
51
63
|
res = client.bucket_list_objects()
|
52
64
|
puts res.success?, res.parsed_response
|
53
65
|
|
54
|
-
With correct parameters, you can get more flexible result.
|
66
|
+
With correct parameters, you can get more flexible result. you can get detailed Paramters [here](http://www.rubydoc.info/gems/aliyun-oss-sdk/Aliyun%2FOss%2FClient%3Abucket_list_objects).
|
67
|
+
|
55
68
|
|
56
69
|
### Step-5. Get special object
|
57
70
|
|
58
71
|
Now, you want to get a special object:
|
59
72
|
|
73
|
+
require 'aliyun/oss'
|
74
|
+
|
75
|
+
access_key, secret_key = "your id", "your secret"
|
76
|
+
host, bucket = "oss-cn-hangzhou.aliyuncs.com", "bucket-name"
|
60
77
|
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
61
78
|
|
62
79
|
res = client.bucket_get_object("test.txt")
|
data/wiki/installation.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
It's a Ruby Gem, so you can install it like any Gem:
|
4
4
|
|
5
|
-
gem install aliyun-oss-sdk
|
5
|
+
$ gem install aliyun-oss-sdk
|
6
6
|
|
7
7
|
If you use Gemfile manage your Gems, Add below to your Gemfile.
|
8
8
|
|
@@ -10,6 +10,6 @@ If you use Gemfile manage your Gems, Add below to your Gemfile.
|
|
10
10
|
|
11
11
|
And run:
|
12
12
|
|
13
|
-
bundle install
|
13
|
+
$ bundle install
|
14
14
|
|
15
15
|
Now, [Getting started](./get_start.md)
|
data/wiki/lifecycle.md
CHANGED
@@ -0,0 +1,75 @@
|
|
1
|
+
## LifeCycle
|
2
|
+
|
3
|
+
OSS provide LifeCycle to help user manage lifecycle of object. User can create LifeCycle rules to manage objects. At present, user can create rule to auto delete Objects. Each rule is composed by following several parts:
|
4
|
+
|
5
|
+
+ Prefix of Object name, only match the prefix will apply this rule.
|
6
|
+
+ Operation, user want to take for the matched objects.
|
7
|
+
+ Date or Days, which user can specify expired date or days to expire.
|
8
|
+
|
9
|
+
|
10
|
+
### Set LifeCycle
|
11
|
+
|
12
|
+
|
13
|
+
In the LifeCycle, you can contains 1000 rules at max.
|
14
|
+
|
15
|
+
Each rule contains:
|
16
|
+
|
17
|
+
+ ID: each rule ID must keep uniqueness and cannot contain others(eg: abc and abcd).
|
18
|
+
+ Prefix: it can used to apply rule for object with the prefix
|
19
|
+
+ Status: defined the status for the rule, Only support Enabled and Disabled.
|
20
|
+
+ Expiration: Date or Days, used to specify expired date or specify expired after x days from last modified date.
|
21
|
+
|
22
|
+
In our Library, to use Struct::LifeCycle to define a rule:
|
23
|
+
|
24
|
+
# Define a rule to auto delete objects with prefix: logs-prod- after 7 days since last modified date
|
25
|
+
rule1 = Aliyun::Oss::Struct::LifeCycle.new({ prefix: 'logs-prod-', days: 7, enable: true })
|
26
|
+
|
27
|
+
# Defome a ri;e tp auto delete objects with prefix: logs-dev- at Time.now + 24*60*60
|
28
|
+
rule2 = Aliyun::Oss::Struct::LifeCycle.new({ prefix: 'logs-dev', date: Time.now + 24*60*60, enable: true })
|
29
|
+
|
30
|
+
|
31
|
+
To set your LifeCycle with this rules:
|
32
|
+
|
33
|
+
require 'aliyun/oss'
|
34
|
+
|
35
|
+
access_key, secret_key = "your id", "your secret"
|
36
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
37
|
+
bucket = "bucket-name"
|
38
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
39
|
+
|
40
|
+
res = client.bucket_enable_lifecycle([rule1, rule2]) puts res.success?, res.headers
|
41
|
+
|
42
|
+
### Get LifeCycle
|
43
|
+
|
44
|
+
To get LifeCycle for bucket, use Client#bucket_get_lifecycle:
|
45
|
+
|
46
|
+
require 'aliyun/oss'
|
47
|
+
|
48
|
+
access_key, secret_key = "your id", "your secret"
|
49
|
+
host = "oss-cn-hangzhou.aliyuncs.com"
|
50
|
+
bucket = "bucket-name"
|
51
|
+
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
52
|
+
|
53
|
+
res = client.bucket_get_lifecycle
|
54
|
+
puts res.success?, res.parsed_response
|
55
|
+
|
56
|
+
|
57
|
+
### Disable LifeCycle
|
58
|
+
|
59
|
+
|
60
|
+
With Client#bucket_disable_lifecycle, you can disable LifeCycle:
|
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_disable_lifecycle
|
71
|
+
puts res.success?, res.headers
|
72
|
+
|
73
|
+
|
74
|
+
Next, Let's discuss about [Error](./error.md)
|
75
|
+
|
data/wiki/multipart.md
CHANGED
@@ -68,13 +68,13 @@ It can used to upload part to a object. Please note:
|
|
68
68
|
bucket = "bucket-name"
|
69
69
|
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
70
70
|
|
71
|
-
part1 = Aliyun::Oss::
|
72
|
-
part2 = Aliyun::Oss::
|
73
|
-
part3 = Aliyun::Oss::
|
71
|
+
part1 = Aliyun::Oss::Struct::Part.new({ number: 1, etag: 'etag1' })
|
72
|
+
part2 = Aliyun::Oss::Struct::Part.new({ number: 2, etag: 'etag2' })
|
73
|
+
part3 = Aliyun::Oss::Struct::Part.new({ number: 3, etag: 'etag3' })
|
74
74
|
res = client.bucket_complete_multipart("Exciting-Ruby.mp4", "Upload ID", [part1, part2, part3])
|
75
75
|
|
76
76
|
|
77
|
-
Here, we create Aliyun::Oss::
|
77
|
+
Here, we create Aliyun::Oss::Struct::Part to build your part, use Part#valid? to valid the object.
|
78
78
|
|
79
79
|
### Abort Multipart Upload
|
80
80
|
|
@@ -121,5 +121,7 @@ Sometimes, you want to know which parts are uploaded.
|
|
121
121
|
|
122
122
|
res = client.bucket_list_parts("Upload ID")
|
123
123
|
puts res.success?, res.parsed_response
|
124
|
+
|
125
|
+
|
126
|
+
OK, It's time to visit [CORS](./cors.md)
|
124
127
|
|
125
|
-
|
data/wiki/object.md
CHANGED
@@ -32,7 +32,7 @@ Client#bucket_create_object support file or bin data to upload.
|
|
32
32
|
puts res.success?, res.headers
|
33
33
|
|
34
34
|
|
35
|
-
The Upload limit Data to 5 GB, if large than
|
35
|
+
The Upload limit Data to 5 GB, if large than, visit [Multipart Upload](./multipart.md).
|
36
36
|
|
37
37
|
|
38
38
|
### Create a folder
|
@@ -49,12 +49,12 @@ To Create a folder, it's easy, just pass key with "/" at last:
|
|
49
49
|
res = client.bucket_create_object("images/", "")
|
50
50
|
puts res.success?, res.headers
|
51
51
|
|
52
|
-
Create simulations folder nature created a size
|
52
|
+
Create simulations folder nature created a object with size equals 0. 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
53
|
|
54
54
|
|
55
55
|
### Customize Http Header for object
|
56
56
|
|
57
|
-
OSS
|
57
|
+
OSS allow users to customize the http headers of object. The following code set the expiration time for the Object:
|
58
58
|
|
59
59
|
require 'aliyun/oss'
|
60
60
|
|
@@ -64,15 +64,15 @@ OSS service allow users to customize the http headers of object. The following c
|
|
64
64
|
client = Aliyun::Oss::Client.new(access_key, secret_key, host: host, bucket: bucket)
|
65
65
|
|
66
66
|
file = File.new("path/to/image.png")
|
67
|
-
res = client.bucket_create_object("image.png", file, { 'Content-Type' => 'image/png', "Expires" => "
|
67
|
+
res = client.bucket_create_object("image.png", file, { 'Content-Type' => 'image/png', "Expires" => "Sun, 25 Oct 2015 05:38:42 GMT" })
|
68
68
|
puts res.success?, res.headers
|
69
69
|
|
70
|
-
Except Expires, also support Cache-Control, Content-Disposition, Content-Encoding, Content-MD5, more details visit: [Client#bucket_create_object]().
|
70
|
+
Except Expires, it also support Cache-Control, Content-Disposition, Content-Encoding, Content-MD5, more details visit: [Client#bucket_create_object](http://www.rubydoc.info/gems/aliyun-oss-sdk/Aliyun%2FOss%2FClient%3Abucket_create_object).
|
71
71
|
|
72
72
|
|
73
73
|
### Set User Meta
|
74
74
|
|
75
|
-
OSS Support meta information for object.
|
75
|
+
OSS Support set some user meta information for object. Here we set x-oss-meta-user to username for object:
|
76
76
|
|
77
77
|
require 'aliyun/oss'
|
78
78
|
|
@@ -86,14 +86,14 @@ OSS Support meta information for object.
|
|
86
86
|
puts res.success?, res.headers
|
87
87
|
|
88
88
|
|
89
|
-
user meta
|
89
|
+
user meta information stored as headers with prefix: "x-oss-meta", the maxinum limit is 2KB for all meta information.
|
90
90
|
|
91
91
|
Note: the user meta key is case-insensitive, but value is case-sensitive.
|
92
92
|
|
93
93
|
|
94
94
|
### Append Upload
|
95
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
|
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
97
|
|
98
98
|
|
99
99
|
require 'aliyun/oss'
|
@@ -114,9 +114,11 @@ OSS Allow users to append data to a object, but only for appendable object, Obje
|
|
114
114
|
res = client.bucket_append_object("secret.zip", "append information", position)
|
115
115
|
puts res.success?, res.headers
|
116
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
|
117
|
+
Users upload with Append mode, the most important is to set position correctly. When a user creates an Appendable Object, additional position to 0. When the Append additional content for Object, the postion is the current length of the object. There are two ways to get the Object length: one is through response after the append upload. Another is fetch with [Client#bucket_get_meta_object(http://www.rubydoc.info/gems/aliyun-oss-sdk/Aliyun/Oss/Client#bucket_get_meta_object-instance_method). the next position information is stored with key --- x-oss-next-append in headers.
|
118
|
+
|
119
|
+
Note: You can set meta information only when create appendable object(the first append). Later, if you want to change the meta, use [Client#bucket_copy_object](http://www.rubydoc.info/gems/aliyun-oss-sdk/Aliyun%2FOss%2FClient%3Abucket_copy_object) -- set source and destination for the same Object.
|
120
|
+
|
118
121
|
|
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
122
|
|
121
123
|
## List objects in Bucket
|
122
124
|
|
@@ -149,7 +151,8 @@ the method support many Parameters to get flexible results:
|
|
149
151
|
res = client.bucket_list_objects(prefix: 'pic', delimiter: '/')
|
150
152
|
puts res.success?, res.parsed_response
|
151
153
|
|
152
|
-
It list results with prefix: pic and end with "/", for example: "pic-people/". More about the Paramters, visit: [Client#bucket_list_objects]()
|
154
|
+
It list results with prefix: pic and end with "/", for example: "pic-people/". More about the Paramters, visit: [Client#bucket_list_objects](http://www.rubydoc.info/gems/aliyun-oss-sdk/Aliyun%2FOss%2FClient%3Abucket_list_objects)
|
155
|
+
|
153
156
|
|
154
157
|
### Get Object
|
155
158
|
|
@@ -163,7 +166,7 @@ It list results with prefix: pic and end with "/", for example: "pic-people/". M
|
|
163
166
|
res = client.bucket_get_object('image.png')
|
164
167
|
puts res.success?, res.parsed_response
|
165
168
|
|
166
|
-
It Support
|
169
|
+
It Support Parameters, Range, If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match. With Range, we can get range data from a object, it's useful for download partly and so on.
|
167
170
|
|
168
171
|
|
169
172
|
### Get Meta Object
|
@@ -180,6 +183,7 @@ To get meta information of a object, use Client#get_meta_object:
|
|
180
183
|
res = client.bucket_get_meta_object('image.png')
|
181
184
|
puts res.success?, res.headers
|
182
185
|
|
186
|
+
|
183
187
|
### Delete Object
|
184
188
|
|
185
189
|
require 'aliyun/oss'
|
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.1.0
|
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-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -94,6 +94,20 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry-byebug
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
97
111
|
- !ruby/object:Gem::Dependency
|
98
112
|
name: webmock
|
99
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +136,20 @@ dependencies:
|
|
122
136
|
- - ">="
|
123
137
|
- !ruby/object:Gem::Version
|
124
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
125
153
|
description: Aliyun OSS Ruby SDK
|
126
154
|
email:
|
127
155
|
- zlx.star@gmail.com
|
@@ -130,6 +158,7 @@ extensions: []
|
|
130
158
|
extra_rdoc_files: []
|
131
159
|
files:
|
132
160
|
- ".gitignore"
|
161
|
+
- ".rubocop.yml"
|
133
162
|
- ".travis.yml"
|
134
163
|
- Gemfile
|
135
164
|
- LICENSE
|
@@ -141,12 +170,26 @@ files:
|
|
141
170
|
- lib/aliyun/oss.rb
|
142
171
|
- lib/aliyun/oss/authorization.rb
|
143
172
|
- lib/aliyun/oss/client.rb
|
173
|
+
- lib/aliyun/oss/client/bucket_multiparts.rb
|
174
|
+
- lib/aliyun/oss/client/bucket_objects.rb
|
175
|
+
- lib/aliyun/oss/client/buckets.rb
|
176
|
+
- lib/aliyun/oss/client/clients.rb
|
177
|
+
- lib/aliyun/oss/error.rb
|
144
178
|
- lib/aliyun/oss/http.rb
|
145
|
-
- lib/aliyun/oss/
|
146
|
-
- lib/aliyun/oss/
|
147
|
-
- lib/aliyun/oss/
|
179
|
+
- lib/aliyun/oss/struct.rb
|
180
|
+
- lib/aliyun/oss/struct/bucket.rb
|
181
|
+
- lib/aliyun/oss/struct/cors.rb
|
182
|
+
- lib/aliyun/oss/struct/lifecycle.rb
|
183
|
+
- lib/aliyun/oss/struct/logging.rb
|
184
|
+
- lib/aliyun/oss/struct/multipart.rb
|
185
|
+
- lib/aliyun/oss/struct/object.rb
|
186
|
+
- lib/aliyun/oss/struct/part.rb
|
187
|
+
- lib/aliyun/oss/struct/referer.rb
|
188
|
+
- lib/aliyun/oss/struct/website.rb
|
148
189
|
- lib/aliyun/oss/utils.rb
|
149
190
|
- lib/aliyun/oss/version.rb
|
191
|
+
- lib/aliyun/oss/xml_generator.rb
|
192
|
+
- todo.md
|
150
193
|
- wiki/bucket.md
|
151
194
|
- wiki/cors.md
|
152
195
|
- wiki/error.md
|
@@ -179,4 +222,3 @@ signing_key:
|
|
179
222
|
specification_version: 4
|
180
223
|
summary: Aliyun OSS Ruby SDK
|
181
224
|
test_files: []
|
182
|
-
has_rdoc:
|