Uploading Objects - Text-Based
API Description
You can use this API to upload the text using character string as the data source of an object to a specified bucket.
Method Definition
ObsClient.putContent(bucketName, objectKey, content, metadata, headers, progressCallback, autoClose)
Request Parameters
| Field | Type | Optional or Mandatory | Description |
|---|---|---|---|
| bucketName | str | Mandatory | Bucket name |
| objectKey | str | Mandatory | Object name or the name of the uploaded object |
| content | str or readable object | Optional | Object content to be uploaded |
| metadata | dict | Optional | Customized metadata of the object |
| headers | Optional | Additional header of the request for uploading an object | |
| progressCallback | callable | Optional | Callback function for obtaining the upload progress NOTE: This function contains the following parameters in sequence: number of uploaded bytes, total number of bytes, and used time (unit: second). For details about the sample code, see Uploading an Object – Obtaining the Upload Progress. Streaming upload, file-based upload, multipart upload, appendable upload, and resumable upload are supported. |
| autoClose | bool | Optional | After the upload is complete, data flow is automatically closed. The default value is True. |
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 Results
| Type | Description |
|---|---|
| SDK common result object |
| GetResult.body Type | Description |
|---|---|
| Response result of the request for uploading an object |
Sample Code
try:
resp = obsClient.putContent('bucketname', 'objectname', content='Hello OBS')
if resp.status < 300:
print('requestId:', resp.requestId)
print('etag:', resp.body.etag)
else:
print('errorCode:', resp.errorCode)
print('errorMessage:', resp.errorMessage)
except:
import traceback
print(traceback.format_exc()) Last Article: Object Upload Overview
Next Article: Uploading Objects - Streaming
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.