Class: Aliyun::Oss::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/aliyun/oss/client/clients.rb,
lib/aliyun/oss/client.rb,
lib/aliyun/oss/client/buckets.rb,
lib/aliyun/oss/client/bucket_objects.rb,
lib/aliyun/oss/client/bucket_multiparts.rb

Overview

Here is some services used to make object based API possible, they are all contains a reference to instance of client, which used to do the real job.

buckets: used to do many buckets operations eg: #list, #create, #delete

client.buckets

bucket_objects: used to do some operation on objects eg: #list, #create, :delete, #copy

client.bucket_objects

bucket_multiparts: used to do some operation for multiparts eg: #init, #list

client.bucket_multiparts

Defined Under Namespace

Modules: BucketMultiparts, BucketObjects, Buckets Classes: BucketMultipartsService, BucketObjectsService, BucketsService, ClientService

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(access_key, secret_key, options = {}) ⇒ Response

Initialize a object

Examples:

Aliyun::Oss::Client.new("ACCESS_KEY", "SECRET_KEY", host: "oss-cn-beijing.aliyuncs.com", bucket: 'oss-sdk-beijing')

Parameters:

  • access_key (String)

    access_key obtained from aliyun

  • secret_key (String)

    secret_key obtained from aliyun

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :host (String)

    host for bucket’s data center

  • :bucket (String)

    Bucket name



20
21
22
23
24
25
26
27
# File 'lib/aliyun/oss/client.rb', line 20

def initialize(access_key, secret_key, options = {})
  @access_key = access_key
  @secret_key = secret_key
  @options = options
  @bucket = options[:bucket]

  @services = {}
end

Instance Attribute Details

#access_keyObject (readonly)

Returns the value of attribute access_key.



6
7
8
# File 'lib/aliyun/oss/client.rb', line 6

def access_key
  @access_key
end

#bucketObject

Returns the value of attribute bucket.



7
8
9
# File 'lib/aliyun/oss/client.rb', line 7

def bucket
  @bucket
end

#secret_keyObject (readonly)

Returns the value of attribute secret_key.



6
7
8
# File 'lib/aliyun/oss/client.rb', line 6

def secret_key
  @secret_key
end

Instance Method Details

#bucket_abort_multipart(upload_id, key) ⇒ Response

Note:

After abort the Multipart Upload, the Uploaded data will be deleted

Note:

When abort a Multipart Upload event, if there are still part upload belonging to this event, then theree parts will not be removed. So if there is a concurrent access, in order to release the space on the OSS completely, you need to call #bucket_abort_multipart a few times.

Abort a Multipart Upload event

Parameters:

  • key (String)

    the object name

  • upload_id (String)

    the upload ID return by #bucket_init_multipart

Returns:

  • (Response)

Raises:

See Also:



652
653
654
655
# File 'lib/aliyun/oss/client.rb', line 652

def bucket_abort_multipart(upload_id, key)
  query = { 'uploadId' => upload_id }
  http.delete("/#{key}", query: query, bucket: bucket, key: key)
end

#bucket_append_object(key, file, position = 0, headers = {}) ⇒ Response

Append data to a object, will create Appendable object

Parameters:

  • key (String)

    object name

  • file (file, bin data)

    the data to append

  • position (Integer) (defaults to: 0)

    append to position of object

  • headers (Hash) (defaults to: {})

    a customizable set of options

Options Hash (headers):

  • :Content-Type (String) — default: 'application/x-www-form-urlencoded'

    Specify Content-Type for the object

  • :Cache-Control (String)

    Specify the caching behavior when download from browser, ref RFC2616

  • :Content-Disposition (String)

    Specify the name when download, ref RFC2616

  • :Content-Encoding (String)

    Specify the content encoding when download, ref RFC2616

  • :Content-MD5 (String)

    RFC 1864 according to the agreement of the message Content (not including head) are calculated MD5 value 128 bits number, the number is base64 encoding for the Content of a message - MD5 value.The legality of the examination of the request headers can be used for information (a message content is consistent with send).Although the request header is optional, OSS recommend that users use the end-to-end check request header.

  • :Expires (Integer)

    Specify the expiration time (milliseconds)

  • :x-oss-server-side-encryption (String)

    Specify the oss server-side encryption algorithm when the object was created. supported value: ‘AES256’

  • :x-oss-object-acl (String)

    Specify the oss access when the object was created. supported value: public-read-write | public-read | private

  • other (Hash)

    options will insert into headers when upload, such as user meta headers, eg: headers with prefix: x-oss-meta-

Returns:

  • (Response)

Raises:

See Also:



431
432
433
434
435
436
437
# File 'lib/aliyun/oss/client.rb', line 431

def bucket_append_object(key, file, position = 0, headers = {})
  query = { 'append' => true, 'position' => position }

  body = Utils.to_data(file)

  http.post("/#{key}", query: query, headers: headers, body: body, bucket: bucket, key: key)
end

#bucket_complete_multipart(upload_id, key, parts = []) ⇒ Response

Complete a Multipart Upload event.

Parameters:

  • key (String)

    object name

  • upload_id (String)

    the upload ID return by #bucket_init_multipart

  • parts (Array<Aliyun::Oss::Multipart:Part>) (defaults to: [])

    parts

Returns:

  • (Response)

Raises:

See Also:



628
629
630
631
632
633
634
635
636
637
# File 'lib/aliyun/oss/client.rb', line 628

def bucket_complete_multipart(upload_id, key, parts = [])
  fail MultipartPartsEmptyError if parts.nil? || parts.empty?
  fail MultipartUploadIdEmptyError if upload_id.nil?

  query = { 'uploadId' => upload_id }

  body = XmlGenerator.generate_complete_multipart_xml(parts)

  http.post("/#{key}", query: query, body: body, bucket: bucket, key: key)
end

#bucket_copy_object(key, source_bucket, source_key, headers = {}) ⇒ Response

Copy an existing object in OSS into another object

Parameters:

  • key (String)

    the object name

  • source_bucket (String)

    the source bucket name

  • source_key (String)

    the source object name

  • headers (Hash) (defaults to: {})
  • options (Hash)

    a customizable set of options

Returns:

  • (Response)

Raises:

See Also:



410
411
412
413
414
415
416
417
# File 'lib/aliyun/oss/client.rb', line 410

def bucket_copy_object(key, source_bucket, source_key, headers = {})
  fail('source_bucket must be not empty!') if source_bucket.nil? || source_bucket.empty?
  fail('source_key must be not empty!') if source_key.nil? || source_key.empty?

  headers.merge!('x-oss-copy-source' => "/#{source_bucket}/#{source_key}")

  http.put("/#{key}", headers: headers, bucket: bucket, key: key)
end

#bucket_create(name, location = 'oss-cn-hangzhou', acl = 'private') ⇒ Response

Create bucket

Examples:

oss.client.bucket_create('oss-sdk-dev-hangzhou-xxx')

Parameters:

  • name (String)

    Specify bucket name

  • location (String) (defaults to: 'oss-cn-hangzhou')

    Specify the bucket’s data center location, can be one of below: oss-cn-hangzhou,oss-cn-qingdao,oss-cn-beijing,oss-cn-hongkong, oss-cn-shenzhen,oss-cn-shanghai,oss-us-west-1 ,oss-ap-southeast-1

  • acl (String) (defaults to: 'private')

    Specify the bucket’s access. (see #bucket_set_acl)

Returns:

  • (Response)

Raises:

See Also:



78
79
80
81
82
83
84
85
# File 'lib/aliyun/oss/client.rb', line 78

def bucket_create(name, location = 'oss-cn-hangzhou', acl = 'private')
  query = { 'acl' => true }
  headers = { 'x-oss-acl' => acl }

  body = XmlGenerator.generate_create_bucket_xml(location)

  http.put('/', query: query, headers: headers, body: body, bucket: name, location: location)
end

#bucket_create_object(key, file, headers = {}) ⇒ Response

Upload file to bucket

Parameters:

  • key (String)

    Specify object name

  • file (File, Bin data)

    Specify need upload resource

  • headers (Hash) (defaults to: {})

    Specify other options

Options Hash (headers):

  • :Content-Type (String) — default: 'application/x-www-form-urlencoded'

    Specify Content-Type for the object

  • :Cache-Control (String)

    Specify the caching behavior when download from browser, ref RFC2616

  • :Content-Disposition (String)

    Specify the name when download, ref RFC2616

  • :Content-Encoding (String)

    Specify the content encoding when download, ref RFC2616

  • :Content-MD5 (String)

    RFC 1864 according to the agreement of the message Content (not including head) are calculated MD5 value 128 bits number, the number is base64 encoding for the Content of a message - MD5 value.The legality of the examination of the request headers can be used for information (a message content is consistent with send).Although the request header is optional, OSS recommend that users use the end-to-end check request header.

  • :Expires (Integer)

    Specify the expiration time (milliseconds)

  • :x-oss-server-side-encryption (String)

    Specify the oss server-side encryption algorithm when the object was created. supported value: ‘AES256’

  • :x-oss-object-acl (String)

    Specify the oss access when the object was created. supported value: public-read-write | public-read | private

  • other (Hash)

    options will insert into headers when upload, such as user meta headers, eg: headers with prefix: x-oss-meta-

Returns:

  • (Response)

See Also:



385
386
387
# File 'lib/aliyun/oss/client.rb', line 385

def bucket_create_object(key, file, headers = {})
  http.put("/#{key}", headers: headers, body: Utils.to_data(file), bucket: bucket, key: key)
end

#bucket_delete(name) ⇒ Response

Delete bucket

Parameters:

  • name (String)

    bucket name want to delete

Returns:

  • (Response)

Raises:

See Also:



96
97
98
# File 'lib/aliyun/oss/client.rb', line 96

def bucket_delete(name)
  http.delete('/', bucket: name)
end

#bucket_delete_object(key) ⇒ Response

Delete object from bucket

Parameters:

  • key (String)

    the object name

Returns:

  • (Response)

See Also:



470
471
472
# File 'lib/aliyun/oss/client.rb', line 470

def bucket_delete_object(key)
  http.delete("/#{key}", bucket: bucket, key: key)
end

#bucket_delete_objects(keys, quiet = false) ⇒ Response

Delete multiple objects, at max 1000 at once

Parameters:

  • keys (Array<String>)

    the object names

  • quiet (Boolean) (defaults to: false)

    Specify response mode: false(Quiet) return results for error objects, true(Verbose) return results of every objects

Returns:

  • (Response)

See Also:



482
483
484
485
486
487
488
# File 'lib/aliyun/oss/client.rb', line 482

def bucket_delete_objects(keys, quiet = false)
  query = { 'delete' => true }

  body = XmlGenerator.generate_delete_objects_xml(keys, quiet)

  http.post('/', query: query, body: body, bucket: bucket)
end

#bucket_disable_corsResponse

Used to disable cors and clear rules for bucket

Returns:

  • (Response)

Raises:

See Also:



262
263
264
265
# File 'lib/aliyun/oss/client.rb', line 262

def bucket_disable_cors
  query = { 'cors' => false }
  http.delete('/', query: query, bucket: bucket)
end

#bucket_disable_lifecycleObject

Used to disable lifecycle for bucket.



223
224
225
226
# File 'lib/aliyun/oss/client.rb', line 223

def bucket_disable_lifecycle
  query = { 'lifecycle' => false }
  http.delete('/', query: query, bucket: bucket)
end

#bucket_disable_loggingResponse

Used to disable access logging.

Returns:

  • (Response)

Raises:

See Also:



140
141
142
143
# File 'lib/aliyun/oss/client.rb', line 140

def bucket_disable_logging
  query = { 'logging' => false }
  http.delete('/', query: query, bucket: bucket)
end

#bucket_disable_websiteResponse

Used to disable website hostted mode.

Returns:

  • (Response)

Raises:

See Also:



170
171
172
173
# File 'lib/aliyun/oss/client.rb', line 170

def bucket_disable_website
  query = { 'website' => false }
  http.delete('/', query: query, bucket: bucket)
end

#bucket_enable_cors(rules = []) ⇒ Response

Used to enable CORS and set rules for bucket

Parameters:

Returns:

  • (Response)

Raises:

See Also:



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/aliyun/oss/client.rb', line 239

def bucket_enable_cors(rules = [])
  query = { 'cors' => true }

  rules = Utils.wrap(rules)

  rules.each do |rule|
    unless rule.valid?
      fail Aliyun::Oss::InvalidCorsRuleError, rule.inspect
    end
  end

  body = XmlGenerator.generate_cors_rules(rules)

  http.put('/', query: query, body: body, bucket: bucket)
end

#bucket_enable_lifecycle(rules = []) ⇒ Response

Used to enable and set lifecycle for bucket

Parameters:

Returns:

  • (Response)

Raises:

See Also:



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/aliyun/oss/client.rb', line 204

def bucket_enable_lifecycle(rules = [])
  query = { 'lifecycle' => true }

  rules = Utils.wrap(rules)

  rules.each do |rule|
    unless rule.valid?
      fail Aliyun::Oss::InvalidLifeCycleRuleError, rule.inspect
    end
  end

  body = XmlGenerator.generate_lifecycle_rules(rules)

  http.put('/', query: query, body: body, bucket: bucket)
end

#bucket_enable_logging(target_bucket, target_prefix = nil) ⇒ Response

Used to enable access logging.

Parameters:

  • target_bucket (String)

    specifies the bucket where you want Aliyun OSS to store server access logs.

  • target_prefix (String) (defaults to: nil)

    this element lets you specify a prefix for the objects that the log files will be stored.

Returns:

  • (Response)

Raises:

See Also:



124
125
126
127
128
129
130
131
# File 'lib/aliyun/oss/client.rb', line 124

def bucket_enable_logging(target_bucket, target_prefix = nil)
  query = { 'logging' => true }

  body = XmlGenerator.generate_enable_logging_xml(target_bucket,
                                                  target_prefix)

  http.put('/', query: query, body: body, bucket: bucket)
end

#bucket_enable_website(suffix, key = nil) ⇒ Response

Used to enable static website hosted mode.

Parameters:

  • suffix (String)

    A suffix that is appended to a request that is for a directory on the website endpoint (e.g. if the suffix is index.html and you make a request to samplebucket/images/ the data that is returned will be for the object with the key name images/index.html) The suffix must not be empty and must not include a slash character.

  • key (String) (defaults to: nil)

    The object key name to use when a 4XX class error occurs

Returns:

  • (Response)

Raises:

See Also:



155
156
157
158
159
160
161
# File 'lib/aliyun/oss/client.rb', line 155

def bucket_enable_website(suffix, key = nil)
  query = { 'website' => true }

  body = XmlGenerator.generate_enable_website_xml(suffix, key)

  http.put('/', query: query, body: body, bucket: bucket)
end

#bucket_get_aclResponse

Get ACL for bucket

Returns:

  • (Response)

See Also:



300
301
302
303
# File 'lib/aliyun/oss/client.rb', line 300

def bucket_get_acl
  query = { 'acl' => true }
  http.get('/', query: query, bucket: bucket)
end

#bucket_get_corsResponse

Get the CORS rules of bucket

Returns:

  • (Response)

See Also:



362
363
364
365
# File 'lib/aliyun/oss/client.rb', line 362

def bucket_get_cors
  query = { 'cors' => true }
  http.get('/', query: query, bucket: bucket)
end

#bucket_get_lifecycleResponse

Get the lifecycle configuration of bucket

Returns:

  • (Response)

See Also:



352
353
354
355
# File 'lib/aliyun/oss/client.rb', line 352

def bucket_get_lifecycle
  query = { 'lifecycle' => true }
  http.get('/', query: query, bucket: bucket)
end

#bucket_get_locationResponse

Get the location information of the Bucket’s data center

Returns:

  • (Response)

See Also:



310
311
312
313
# File 'lib/aliyun/oss/client.rb', line 310

def bucket_get_location
  query = { 'location' => true }
  http.get('/', query: query, bucket: bucket)
end

#bucket_get_loggingResponse

Get the log configuration of Bucket

Returns:

  • (Response)

Raises:

See Also:



322
323
324
325
# File 'lib/aliyun/oss/client.rb', line 322

def bucket_get_logging
  query = { 'logging' => true }
  http.get('/', query: query, bucket: bucket)
end

#bucket_get_meta_object(key, headers = {}) ⇒ Response

Get meta information of object

Parameters:

  • key (String)

    object name

  • headers (Hash) (defaults to: {})

    headers

Options Hash (headers):

  • :If-Modified-Since (String)

    If the specified time is earlier than the file last modification time, return 200 OK; Otherwise returns 304(not modified)

  • :If-Unmodified-Since (String)

    If the specified time is equal to or later than the file last modification time, normal transfer ans return 200; Otherwise returns 412(precondition)

  • :If-Match (String)

    If the specified ETag match the object ETag, normal transfer and return 200; Otherwise return 412(precondition)

  • :If-None-Match (String)

    If the specified ETag not match the object ETag, normal transfer and return 200; Otherwise return 304(Not Modified)

Returns:

  • (Response)

Raises:

See Also:



504
505
506
# File 'lib/aliyun/oss/client.rb', line 504

def bucket_get_meta_object(key, headers = {})
  http.head("/#{key}", headers: headers, bucket: bucket, key: key)
end

#bucket_get_object(key, query = {}, headers = {}) ⇒ Response

Get the object

Parameters:

  • key (String)

    the object name

  • query (Hash) (defaults to: {})

    query params

  • headers (Hash) (defaults to: {})

    headers

Options Hash (query):

  • :response-content-type (String)

    Specify the header Content-Type in response

  • :response-content-language (String)

    Specify the header Content-Language in response

  • :response-expires (String)

    Specify the header Expires in response

  • :response-cache-control (String)

    Specify the header Cache-Control in response

  • :response-content-disposition (String)

    Specify the header Content-Disposition in response

  • :response-content-encoding (String)

    Specify the header Content-encoding in response

Options Hash (headers):

  • :Range (String)

    Specify the range of the file. Such as “bytes=0-9” means the 10 characters from 0 to 9.

  • :If-Modified-Since (String)

    If the specified time is earlier than the file last modification time, return 200 OK; Otherwise returns 304(not modified)

  • :If-Unmodified-Since (String)

    If the specified time is equal to or later than the file last modification time, normal transfer ans return 200; Otherwise returns 412(precondition)

  • :If-Match (String)

    If the specified ETag match the object ETag, normal transfer and return 200; Otherwise return 412(precondition)

  • :If-None-Match (String)

    If the specified ETag not match the object ETag, normal transfer and return 200; Otherwise return 304(Not Modified)

Returns:

  • (Response)

See Also:



459
460
461
# File 'lib/aliyun/oss/client.rb', line 459

def bucket_get_object(key, query = {}, headers = {})
  http.get("/#{key}", query: query, headers: headers, bucket: bucket, key: key)
end

#bucket_get_object_acl(key) ⇒ Response

Get access of object

Parameters:

  • key (String)

    object name

Returns:

  • (Response)

Raises:

See Also:



517
518
519
520
# File 'lib/aliyun/oss/client.rb', line 517

def bucket_get_object_acl(key)
  query = { 'acl' => true }
  http.get("/#{key}", query: query, bucket: bucket, key: key)
end

#bucket_get_refererResponse

Get the referer configuration of bucket

Returns:

  • (Response)

See Also:



342
343
344
345
# File 'lib/aliyun/oss/client.rb', line 342

def bucket_get_referer
  query = { 'referer' => true }
  http.get('/', query: query, bucket: bucket)
end

#bucket_get_websiteResponse

Get the bucket state of static website hosting.

Returns:

  • (Response)

See Also:



332
333
334
335
# File 'lib/aliyun/oss/client.rb', line 332

def bucket_get_website
  query = { 'website' => true }
  http.get('/', query: query, bucket: bucket)
end

#bucket_init_multipart(key, headers = {}) ⇒ Response

Initialize a Multipart Upload event, before using Multipart Upload mode to transmit data, we has to call the interface to notify the OSS initialize a Multipart Upload events.

Parameters:

  • key (String)

    object name

  • headers (Hash) (defaults to: {})

    headers

Options Hash (headers):

Returns:

  • (Response)

See Also:



552
553
554
555
# File 'lib/aliyun/oss/client.rb', line 552

def bucket_init_multipart(key, headers = {})
  query = { 'uploads' => true }
  http.post("/#{key}", query: query, headers: headers, bucket: bucket, key: key)
end

#bucket_list_multiparts(options = {}) ⇒ Response

List existing opened Multipart Upload event.

Parameters:

  • options (Hash) (defaults to: {})

    options

Options Hash (options):

  • :prefix (String)

    Filter objects with prefix

  • :delimiter (String)

    Used to group objects with delimiter

  • :max-uploads (Integer) — default: 1000

    Limit number of Multipart Upload events, the maxinum should <= 1000

  • :encoding-type (String)

    Encoding type used for unsupported character

  • :key-marker (String)

    with upload-id-marker used to specify the result range.

  • :upload-id-marker (String)

    with key-marker used to specify the result range.

Returns:

  • (Response)

See Also:



670
671
672
673
674
675
676
677
# File 'lib/aliyun/oss/client.rb', line 670

def bucket_list_multiparts(options = {})
  accepted_keys = ['prefix', 'key-marker', 'upload-id-marker', 'max-uploads', 'delimiter', 'encoding-type']

  query = Utils.hash_slice(options, *accepted_keys)
          .merge('uploads' => true)

  http.get('/', query: query, bucket: bucket)
end

#bucket_list_objects(options = {}) ⇒ Response

List objects in the bucket

Parameters:

  • options (Hash) (defaults to: {})

    options

Options Hash (options):

  • :prefix (String)

    Filter objects with prefix

  • :marker (String)

    Result should after marker in alphabetical order

  • :max-keys (Integer) — default: 100

    Limit number of objects, the maxinum should <= 1000

  • :delimiter (String)

    Used to group objects with delimiter

  • :encoding-type (String)

    Encoding type used for unsupported character

Returns:

  • (Response)

See Also:



56
57
58
59
60
# File 'lib/aliyun/oss/client.rb', line 56

def bucket_list_objects(options = {})
  accepted_keys = ['prefix', 'marker', 'max-keys', 'delimiter', 'encoding-type']
  query = Utils.hash_slice(options, *accepted_keys)
  http.get('/', query: query, bucket: bucket)
end

#bucket_list_parts(upload_id, key, options = {}) ⇒ Response

List uploaded parts for Multipart Upload event

Parameters:

  • key (String)

    the object name

  • upload_id (Integer)

    the upload ID return by #bucket_init_multipart

  • options (Hash) (defaults to: {})

    options

Options Hash (options):

  • :max-parts (Integer) — default: 1000

    Limit number of parts, the maxinum should <= 1000

  • :part-number-marker (Integer)

    Specify the start part, return parts which number large than the specified value

  • :encoding-type (String)

    Encoding type used for unsupported character in xml 1.0

Returns:

  • (Response)

See Also:



691
692
693
694
695
696
697
# File 'lib/aliyun/oss/client.rb', line 691

def bucket_list_parts(upload_id, key, options = {})
  accepted_keys = ['max-parts', 'part-number-marker', 'encoding-type']

  query = Utils.hash_slice(options, *accepted_keys).merge('uploadId' => upload_id)

  http.get("/#{key}", query: query, bucket: bucket, key: key)
end

#bucket_multipart_copy_upload(upload_id, key, number, options = {}) ⇒ Response

Upload a Part from an existing Object Copy data.

Parameters:

  • key (String)

    object name

  • number (Integer)

    the part number, Range in 1~10000.

  • upload_id (String)

    the upload ID return by #bucket_init_multipart

  • options (Hash) (defaults to: {})

    options

Options Hash (options):

  • :source_bucket (String)

    the source bucket name

  • :source_key (String)

    the source object name

  • :range (String)

    the Range bytes, not set means the whole object, eg: bytes=100-6291756

  • :x-oss-copy-source-if-match (String)

    If the specified ETag match the source object ETag, normal transfer and return 200; Otherwise return 412(precondition)

  • :x-oss-copy-source-if-none-match (String)

    If the specified ETag not match the source object ETag, normal transfer and return 200; Otherwise return 304(Not Modified)

  • :x-oss-copy-source-if-unmodified-since (String)

    If the specified time is equal to or later than the source object last modification time, normal transfer ans return 200; Otherwise returns 412(precondition)

  • :x-oss-copy-source-if-modified-since (String)

    If the specified time is earlier than the source object last modification time, normal transfer ans return 200; Otherwise returns 304(not modified)

Returns:

  • (Response)

Raises:

See Also:



601
602
603
604
605
606
607
608
609
610
611
612
613
# File 'lib/aliyun/oss/client.rb', line 601

def bucket_multipart_copy_upload(upload_id, key, number, options = {})
  source_bucket = options.delete(:source_bucket).to_s
  source_key = options.delete(:source_key).to_s
  range = options.delete(:range)

  fail MultipartSourceBucketEmptyError if source_bucket.empty?
  fail MultipartSourceKeyEmptyError if source_key.empty?

  query = { 'partNumber' => number, 'uploadId' => upload_id }
  headers = copy_upload_headers(source_bucket, source_key, range, options)

  http.put("/#{key}", query: query, headers: headers, bucket: bucket, key: key)
end

#bucket_multipart_upload(upload_id, key, number, file) ⇒ Response

Upload object in part.

Parameters:

  • key (String)

    object name

  • number (Integer)

    the part number, Range in 1~10000.

  • upload_id (String)

    the upload ID return by #bucket_init_multipart

  • file (File, bin data)

    the upload data

Returns:

  • (Response)

Raises:

  • (RequestError)
  • (MultipartPartNumberEmptyError)
  • (MultipartUploadIdEmptyError)

See Also:



571
572
573
574
575
576
577
578
# File 'lib/aliyun/oss/client.rb', line 571

def bucket_multipart_upload(upload_id, key, number, file)
  fail MultipartPartNumberEmptyError if number.nil?
  fail MultipartUploadIdEmptyError if upload_id.nil? || upload_id.empty?

  query = { 'partNumber' => number.to_s, 'uploadId' => upload_id }

  http.put("/#{key}", query: query, body: Utils.to_data(file), bucket: bucket, key: key)
end

#bucket_multipartsObject



28
29
30
31
# File 'lib/aliyun/oss/client/clients.rb', line 28

def bucket_multiparts
  @services[:bucket_multiparts] ||= \
    Client::BucketMultipartsService.new(self)
end

#bucket_objectsObject



24
25
26
# File 'lib/aliyun/oss/client/clients.rb', line 24

def bucket_objects
  @services[:bucket_objects] ||= Client::BucketObjectsService.new(self)
end

#bucket_preflight(object_key, origin, request_method, request_headers = []) ⇒ Response

OPTIONS Object

Parameters:

  • object_key (String)

    the object name want to visit.

  • origin (String)

    the requested source domain, denoting cross-domain request.

  • request_method (String)

    the actual request method will be used.

  • request_headers (Array<String>) (defaults to: [])

    the actual used headers except simple headers will be used.

Returns:

  • (Response)

Raises:

See Also:



279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'lib/aliyun/oss/client.rb', line 279

def bucket_preflight(object_key, origin, request_method, request_headers = [])
  path = object_key ? "/#{object_key}" : '/'

  headers = {
    'Origin' => origin,
    'Access-Control-Request-Method' => request_method
  }

  unless request_headers.empty?
    value = request_headers.join(',')
    headers.merge!('Access-Control-Request-Headers' => value)
  end

  http.options(path, headers: headers, bucket: bucket, key: object_key)
end

#bucket_set_acl(acl) ⇒ Response

Used to modify the bucket access.

Parameters:

  • acl (String)

    supported value: public-read-write | public-read | private

Returns:

  • (Response)

Raises:

See Also:



108
109
110
111
112
# File 'lib/aliyun/oss/client.rb', line 108

def bucket_set_acl(acl)
  query = { 'acl' => true }
  headers = { 'x-oss-acl' => acl }
  http.put('/', query: query, headers: headers, bucket: bucket)
end

#bucket_set_object_acl(key, acl) ⇒ Response

Set access of object

Parameters:

  • key (String)

    object name

  • acl (String)

    access value, supported value: private, public-read, public-read-write

Returns:

  • (Response)

Raises:

See Also:



532
533
534
535
536
# File 'lib/aliyun/oss/client.rb', line 532

def bucket_set_object_acl(key, acl)
  query = { 'acl' => true }
  headers = { 'x-oss-object-acl' => acl }
  http.put("/#{key}", query: query, headers: headers, bucket: bucket, key: key)
end

#bucket_set_referer(referers = [], allowed_empty = false) ⇒ Response

Used to set referer for bucket.

Parameters:

  • referers (Array<String>) (defaults to: [])

    white list for allowed referer.

  • allowed_empty (Boolean) (defaults to: false)

    whether allow empty refer.

Returns:

  • (Response)

Raises:

See Also:



185
186
187
188
189
190
191
# File 'lib/aliyun/oss/client.rb', line 185

def bucket_set_referer(referers = [], allowed_empty = false)
  query = { 'referer' => true }

  body = XmlGenerator.generate_set_referer_xml(referers, allowed_empty)

  http.put('/', query: query, body: body, bucket: bucket)
end

#bucketsObject



20
21
22
# File 'lib/aliyun/oss/client/clients.rb', line 20

def buckets
  @services[:buckets] ||= Client::BucketsService.new(self)
end

#list_buckets(options = {}) ⇒ Response

List buckets

Parameters:

  • options (Hash) (defaults to: {})

    options

Options Hash (options):

  • :prefix (String)

    Filter buckets with prefix

  • :marker (String)

    Bucket name should after marker in alphabetical order

  • :max-keys (Integer) — default: 100

    Limit number of buckets, the maxinum should <= 1000

Returns:

  • (Response)

See Also:



39
40
41
42
# File 'lib/aliyun/oss/client.rb', line 39

def list_buckets(options = {})
  query = Utils.hash_slice(options, 'prefix', 'marker', 'max-keys')
  http.get('/', query: query)
end