• Object Storage Service

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

PUT Object

API Description

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

Method Definition

1. ObsClient.putContent(bucketName, objectKey, content, metadata, headers)
2.ObsClient.putObject(bucketName, objectKey, content, metadata, headers)

Request Parameter

Field

Type

Optional or Mandatory

Description

bucketName

str

Mandatory

Bucket name

objectKey

str

Mandatory

Object name

content

str

or

readable object

Optional

Object content to be uploaded

metadata

dict

Optional

Customized metadata of the object

headers

PutObjectHeader

Optional

Additional headers in PUT Object

NOTE:

If content is a readable object that contains the read attribute, data can be read from content. Otherwise, the object content is a character string.

Returned Result

Type

Description

GetResult

SDK common result object

GetResult.body Type

Description

PutContentResponse

Response result of PUT Object

Sample Code

try:
    from com.obs.models.put_object_header import PutObjectHeader 
     
    headers = PutObjectHeader() 
    headers.contentType = 'text/plain' 
    resp = obsClient.putContent('bucketname', 'objectkey', 'Hello OBS', metadata={'meta1':'value1', 'meta2':'value2'}, headers=headers) 
          
    if resp.status < 300: 
        print('requestId:', resp.requestId) 
        print('etag:', resp.body.etag) 
        print('versionId:', resp.body.versionId) 
        print('storageClass:', resp.body.storageClass) 
    else: 
        print('errorCode:', resp.errorCode) 
        print('errorMessage:', resp.errorMessage)
except:
    import traceback
    print(traceback.format_exc())