You can download objects stored in Object Storage Service (OSS) by using OSS SDK for Ruby. You can also directly download the objects over HTTP. To download an object over HTTP, you can use a browser or a command-line tool such as wget curl. In this case, you must use OSS SDK for Ruby to generate the URL of the object.

If you use the Bucket#object_url method to generate an HTTP address used to download the object, you must configure the following parameters:
  • key: the name of the object that you want to download.
  • sign: specifies whether to generate a signed URL.
    Note
    • If the access control list (ACL) of the object is public read or public read/write, you can access the object by using a URL that does not contain a signature.
    • If the ACL of the object is private, you must use a signed URL to access the object.
  • expires: the validity period of the URL. Default value: 60. Unit: seconds.

Examples

The following code provides an example on how to perform HTTP-based download:

require 'aliyun/oss'

client = Aliyun::OSS::Client.new(
  # In this example, the endpoint of the China (Hangzhou) region is used. Specify your actual endpoint. 
  endpoint: 'https://oss-cn-hangzhou.aliyuncs.com',
  # The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  access_key_id: 'AccessKeyId', access_key_secret: 'AccessKeySecret')

# Specify the bucket name. Example: examplebucket. 
bucket = client.get_bucket('examplebucket')
# Generate a URL. By default, the URL contains a signature. The validity period is 60 seconds. 
puts bucket.object_url('my-object')
# https://examplebucket.oss-cn-hangzhou.aliyuncs.com/my-object?Expires=1448349966&OSSAccessKeyId=5vxxxx&Signature=aM2HpBLeMq1aec6JCd7BBAKYiwI%3D

# Generate a URL that does not contain a signature. 
puts bucket.object_url('my-object', false)
# https://examplebucket.oss-cn-hangzhou.aliyuncs.com/my-object

# Set the validity period of the specified URL to 3600 seconds. 
puts bucket.object_url('my-object', true, 3600)