Uploading an Object – Obtaining the Upload Progress
You can set the callback function to obtain upload progress. Sample code is as follows:
# Import the module.
from obs import ObsClient
# Create an ObsClient instance.#
obsClient = ObsClient(
access_key_id='*** Provide your Access Key ***',
secret_access_key='*** Provide your Secret Key ***',
server='https://your-endpoint'
)
def callback(transferredAmount, totalAmount, totalSeconds):
# Obtain the average upload rate (KB/s).
print(transferredAmount * 1.0 / totalSeconds / 1024)
# Obtain the upload progress in percentage.
print(transferredAmount * 100.0 / totalAmount)
resp = obsClient.putFile('bucketname', 'objectname', file_path='localfile', progressCallback=callback)
if resp.status < 300:
print('requestId:', resp.requestId)
else:
print('errorCode:', resp.errorCode)
print('errorMessage:', resp.errorMessage)
You can query the upload progress when uploading an object in streaming, file-based, multipart, appendable, or resumable mode.
Last Article: Uploading Objects - Resumable Transfer
Next Article: Uploading Objects - Browser-Based
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.