• Object Storage Service

obs
  1. Help Center
  2. Object Storage Service
  3. API Reference (Python SDK)
  4. Objects-Related APIs
  5. GET Object

GET Object

API Description

You can use this API to download an object in a specified bucket.

Method Definition

ObsClient.getObject(bucketName, objectKey, downloadPath, getObjectRequest, headers, loadStreamInMemory)

Request Parameter

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

objectKey

str

Mandatory

Object name

downloadPath

str

Optional

Target path to which the object is downloaded (containing the file name)

getObjectRequest

GetObjectRequest

Optional

Additional request parameter of GET Object

headers

GetObjectHeader

Optional

Additional headers in GET Object

loadStreamInMemory

bool

Optional

Whether to load the data stream of the object to the memory. The default value is False. If the value is True, the downloadPath parameter will be ineffective and the obtained data stream will be directly loaded to the memory.

Returned Result

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

ObjectStream

Response result of GET Object

Sample Code

try:
    from com.obs.models.get_object_header import GetObjectHeader 
     
    headers = GetObjectHeader() 
    headers.range = '0-10' 
     
    resp = obsClient.getObject('bucketname', 'objectkey', headers=headers, loadStreamInMemory=True) 
          
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
        print('buffer:', resp.body.buffer) 
        print('size:', resp.body.size) 
        print('contentLength', resp.body.contentLength) 
        print('etag', resp.body.etag) 
        print('lastModified', resp.body.lastModified) 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())