module Aliyun::Oss::API

Reference docs-aliyun-com-cn-b.oss-cn-hangzhou.aliyuncs.com/oss/pdf/oss_api-reference.pdf

Public Instance Methods

copy_object(source_bucket, source_path, target_bucket, target_path, headers = {}) click to toggle source

Copy Object

# File lib/aliyunoss/api.rb, line 155
def copy_object(source_bucket, source_path, target_bucket, target_path, headers = {})
  headers = headers.merge({'x-oss-copy-source'=> "/" + source_bucket.name + source_path})
  Aliyun::Oss::OssRequest.new(target_bucket, target_path, nil, {}, headers).put
end
create_bucket(name, location = 'oss-cn-hangzhou')
Alias for: put_bucket
delete_bucket(bucket) click to toggle source

Delete a bucket

# File lib/aliyunoss/api.rb, line 37
def delete_bucket(bucket)
  Aliyun::Oss::OssRequest.new(bucket, '/').delete
end
delete_logging(bucket) click to toggle source

Delete bucket logging

# File lib/aliyunoss/api.rb, line 44
def delete_logging(bucket)
  Aliyun::Oss::OssRequest.new(bucket, '/', nil, 'logging'=>nil).delete
end
delete_multiple_objects(bucket, objects, quiet_mode = false) click to toggle source

Delete Multiple Object

# File lib/aliyunoss/api.rb, line 170
def delete_multiple_objects(bucket, objects, quiet_mode = false)
  xml = '<?xml version="1.0" encoding="UTF-8"?>'
  xml << '<Delete>'
  xml << "<Quiet>#{quiet_mode}</Quiet>"
  objects.each {|o| xml << "<Object><Key>#{o}</Key></Object>"}
  xml << '</Delete>'
  request = Aliyun::Oss::OssRequest.new(bucket, '/', nil, 'delete'=>nil)
  request.body = xml
  request.post
end
delete_object(bucket, path) click to toggle source

Delete Object

# File lib/aliyunoss/api.rb, line 163
def delete_object(bucket, path)
  Aliyun::Oss::OssRequest.new(bucket, path).delete
end
delete_website(bucket) click to toggle source

Delete bucket website

# File lib/aliyunoss/api.rb, line 51
def delete_website(bucket)
  Aliyun::Oss::OssRequest.new(bucket, '/', nil, 'website'=>nil).delete
end
Also aliased as: disable_website
disable_bucket_logging(bucket) click to toggle source

Disable bucket logging

# File lib/aliyunoss/api.rb, line 120
      def disable_bucket_logging(bucket)
        request = Aliyun::Oss::OssRequest.new(bucket, '/', nil, 'logging'=>nil)
        request.body = <<HERE
<?xml version="1.0" encoding="UTF-8"?>
<BucketLoggingStatus>
</BucketLoggingStatus>
HERE
        request['Content-Type'] = 'application/xml'
        request.put        
      end
disable_website(bucket)
Alias for: delete_website
enable_bucket_logging(bucket, bucket_name_for_logging, log_prefix) click to toggle source

Enable bucket logging

# File lib/aliyunoss/api.rb, line 102
      def enable_bucket_logging(bucket, bucket_name_for_logging, log_prefix)
        request = Aliyun::Oss::OssRequest.new(bucket, '/', nil, 'logging'=>nil)
        request.body = <<HERE
<?xml version="1.0" encoding="UTF-8"?>
<BucketLoggingStatus>
  <LoggingEnabled>
    <TargetBucket>#{bucket_name_for_logging}</TargetBucket>
    <TargetPrefix>#{log_prefix}</TargetPrefix>
  </LoggingEnabled>
</BucketLoggingStatus>
HERE
        request['Content-Type'] = 'application/xml'
        request.put
      end
generate_share_url(bucket, path, expires_in = 3600) click to toggle source

get share url for specified object

# File lib/aliyunoss/api.rb, line 207
def generate_share_url(bucket, path, expires_in = 3600)
  Aliyun::Oss::OssRequest.new(bucket, path).url_for_sharing(expires_in)
end
get_bucket_acl(bucket) click to toggle source

Get bucket acl

# File lib/aliyunoss/api.rb, line 66
def get_bucket_acl(bucket)
  Aliyun::Oss::OssRequest.new(bucket, '/', nil, 'acl'=>nil).get
end
get_bucket_location(bucket) click to toggle source

Get bucket location

# File lib/aliyunoss/api.rb, line 73
def get_bucket_location(bucket)
  Aliyun::Oss::OssRequest.new(bucket, '/', nil, 'location'=>nil).get
end
get_bucket_logging(bucket) click to toggle source

Query bucket logging status

# File lib/aliyunoss/api.rb, line 80
def get_bucket_logging(bucket)
  Aliyun::Oss::OssRequest.new(bucket, '/', nil, 'logging'=>nil).get
end
get_bucket_website(bucket) click to toggle source

Query bucket website status

# File lib/aliyunoss/api.rb, line 87
def get_bucket_website(bucket)
  Aliyun::Oss::OssRequest.new(bucket, '/', nil, 'website'=>nil).get
end
get_object(bucket, path, headers = {}) click to toggle source

Get Object

# File lib/aliyunoss/api.rb, line 184
def get_object(bucket, path, headers = {})
  Aliyun::Oss::OssRequest.new(bucket, path, nil, {}, headers).get
end
get_service(params = {})
Alias for: list_bucket
head_object(bucket, path, headers = {}) click to toggle source

Head Object

# File lib/aliyunoss/api.rb, line 191
def head_object(bucket, path, headers = {})
  Aliyun::Oss::OssRequest.new(bucket, path, nil, {}, headers).head
end
list_bucket(params = {}) click to toggle source

List all buckets

# File lib/aliyunoss/api.rb, line 13
def list_bucket(params = {})
  Aliyun::Oss::OssRequest.new(nil, '/', nil, {}, {}).get
end
Also aliased as: get_service
list_object(bucket, queries = {}) click to toggle source

List objects in bucket

# File lib/aliyunoss/api.rb, line 59
def list_object(bucket, queries = {})
  Aliyun::Oss::OssRequest.new(bucket, '/', nil, queries).get
end
multipart_upload_abort(bucket, path, upload_id) click to toggle source

Abort an upload task

# File lib/aliyunoss/api.rb, line 269
def multipart_upload_abort(bucket, path, upload_id)
  Aliyun::Oss::OssRequest.new(bucket, path, nil, 'uploadId'=> upload_id).delete
end
multipart_upload_complete(bucket, path, upload_id, part_list) click to toggle source

Complete an multipart upload.

# File lib/aliyunoss/api.rb, line 256
def multipart_upload_complete(bucket, path, upload_id, part_list)
  request = Aliyun::Oss::OssRequest.new(bucket, path, nil, 'uploadId'=> upload_id)
  xml = '<?xml version="1.0" encoding="UTF-8"?>'   
  xml << '<CompleteMultipartUpload>'
  part_list.each_pair {|k,v| xml << "<Part><PartNumber>#{k}</PartNumber><ETag>#{v}</ETag></Part>"}
  xml << '</CompleteMultipartUpload>'
  request.body = xml
  request.post
end
multipart_upload_finished_parts(bucket, path, upload_id) click to toggle source

List finished multipart parts

# File lib/aliyunoss/api.rb, line 276
def multipart_upload_finished_parts(bucket, path, upload_id)
  Aliyun::Oss::OssRequest.new(bucket, path, nil, 'uploadId'=> upload_id).get
end
multipart_upload_from_copy(upload_id, source_bucket, source_path, target_bucket, target_path, part_number, part_size, range = nil) click to toggle source

Multipart upload from copy

# File lib/aliyunoss/api.rb, line 245
def multipart_upload_from_copy(upload_id, source_bucket, source_path, target_bucket, target_path, part_number, part_size, range = nil)
  request = Aliyun::Oss::OssRequest.new(target_bucket, target_path, nil, 'partNumber'=> part_number.to_s, 'uploadId'=> upload_id)
  request['Content-Length'] = part_size
  request['x-oss-copy-source'] = "/" + source_bucket.name + source_path
  request['x-oss-copy-source-range'] = range if range
  request.put
end
multipart_upload_initiate(bucket, path) click to toggle source

Multipart Initiate

# File lib/aliyunoss/api.rb, line 229
def multipart_upload_initiate(bucket, path)
  Aliyun::Oss::OssRequest.new(bucket, path, nil, 'uploads'=>nil).post
end
multipart_upload_part(bucket, path, upload_id, data, part_number) click to toggle source

Multipart upload part

# File lib/aliyunoss/api.rb, line 236
def multipart_upload_part(bucket, path, upload_id, data, part_number)
  request = Aliyun::Oss::OssRequest.new(bucket, path, nil, 'partNumber'=> part_number.to_s, 'uploadId'=> upload_id)
  request.body = data
  request.put
end
multipart_upload_unfinished_task(bucket) click to toggle source

List all unfinished multipart task

# File lib/aliyunoss/api.rb, line 283
def multipart_upload_unfinished_task(bucket)
  Aliyun::Oss::OssRequest.new(bucket, '/', nil, 'uploads'=>nil).get
end
put_bucket(name, location = 'oss-cn-hangzhou') click to toggle source

Create a new bucket

# File lib/aliyunoss/api.rb, line 21
      def put_bucket(name, location = 'oss-cn-hangzhou')
        bucket = Bucket.new(name: name, location: location)
        request = Aliyun::Oss::OssRequest.new(bucket, '/')
        request.body = <<HERE

<CreateBucketConfiguration>
<LocationConstraint>#{location}</LocationConstraint>
</CreateBucketConfiguration>
HERE
        request.put
      end
Also aliased as: create_bucket
put_bucket_acl(bucket, permission) click to toggle source

Set bucket acl permission

# File lib/aliyunoss/api.rb, line 94
def put_bucket_acl(bucket, permission)
  Aliyun::Oss::OssRequest.new(bucket, '/', nil, {}, 'x-oss-acl'=> permission).put
end
Also aliased as: set_bucket_acl
put_bucket_website(bucket, index_page, error_page) click to toggle source

Set bucket website access

# File lib/aliyunoss/api.rb, line 134
      def put_bucket_website(bucket, index_page, error_page)
        request = Aliyun::Oss::OssRequest.new(bucket, '/', nil, 'website'=>nil)
        request.body = <<HERE
<?xml version="1.0" encoding="UTF-8"?>
<WebsiteConfiguration>
  <IndexDocument>
    <Suffix>#{index_page}</Suffix>
  </IndexDocument>
  <ErrorDocument>
    <Key>#{error_page}</Key>
  </ErrorDocument>
</WebsiteConfiguration>
HERE
        request['Content-Type'] = 'application/xml'
        request.put
      end
Also aliased as: set_bucket_website
put_object(bucket, path, data, headers = {}) click to toggle source

Put Object

# File lib/aliyunoss/api.rb, line 198
def put_object(bucket, path, data, headers = {})
  request = Aliyun::Oss::OssRequest.new(bucket, path, nil, {}, headers)
  request.body = data
  request.put
end
set_bucket_acl(bucket, permission)
Alias for: put_bucket_acl
set_bucket_website(bucket, index_page, error_page)
Alias for: put_bucket_website