• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. Developer Guide (Python SDK)
  4. Object Download
  5. Downloading a Cold Object

Downloading a Cold Object

If you want to download a Cold object, you need to restore the object first. Three restore options are supported, as described in the following table.

Option

Description

Expedited

Data can be restored within 1 to 5 minutes.

Standard

Data can be restored within 3 to 5 hours. This is the default option.

Bulk

Data can be restored within 5 to 12 hours.

You can call ObsClient.restoreObject to restore a Cold object. Sample code is as follows:

# Import the module.
from com.obs.client.obs_client import ObsClient
# Create an instance of ObsClient.
obsClient = ObsClient(
    access_key_id='*** Provide your Access Key ***',    
    secret_access_key='*** Provide your Secret Key ***',    
    server='yourdomainname'
)

# Restore a Cold object.
resp = obsClient.restoreObject('bucketname', 'objectkey', days=1, tier='Expedited')
if resp.status < 300:
    print('requestId:', resp.requestId)
    # Wait until the object is restored.
    import time
    time.sleep(60 * 6)
# Download an object.
    resp2 = obsClient.getObject('bucketname', 'objectkey', loadStreamInMemory=True)
    if resp2.status < 300:    
        print('requestId:', resp2.requestId)    
        # Obtain the object content.    
        print('buffer:', resp2.body.buffer)    
        print('size:',resp2.body.size)
    else:    
        print('errorCode:', resp2.errorCode)
        print('errorMessage:', resp2.errorMessage)
else:
    print('errorCode:', resp.errorCode)
    print('errorMessage:', resp.errorMessage)
NOTE:
  • The object specified in ObsClient.restoreObject must be in the OBS Cold storage class. Otherwise, an error will be reported when you call this API.
  • Use the days parameter to specify the retention period of to-be-restored objects, the parameter value ranges from 1 to 30. Use the tier parameter to specify the restore option that indicates the time consumed for restoring objects.