Obtaining Upload Progress
If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference
You can call PutObjectRequest.UploadProgress to register with the System.EventHandler callback function to obtain upload progress. Sample code is as follows:
// Create an instance of ObsClient.
ObsClient client = new ObsClient("*** Provide your Access Key ***", "*** Provide your Secret Key ***", "https://your-endpoint");
// Upload a file.
try
{
PutObjectRequest request = new PutObjectRequest()
{
BucketName = "bucketname",
ObjectKey = "objectname",
FilePath = "localfile",// Path of the local file uploaded. The file name must be specified.
};
// Represent the progress by showing how many bytes have been uploaded.
request.ProgressType = ProgressTypeEnum.ByBytes;
// Refresh the upload progress each time 1 MB data is uploaded.
request.ProgressInterval = 1024 * 1024;
// Register the upload progress callback function.
request.UploadProgress += delegate(object sender, TransferStatus status){
// Obtain the average upload rate.
Console.WriteLine("AverageSpeed: {0}", status.AverageSpeed / 1024 + "KB/S");
// Obtain the upload progress in percentage.
Console.WriteLine("TransferPercentage: {0}", status.TransferPercentage);
};
PutObjectResponse response = client.PutObject(request);
Console.WriteLine("put object response: {0}", response.StatusCode);
}
catch (ObsException ex)
{
Console.WriteLine("ErrorCode: {0}", ex.ErrorCode);
Console.WriteLine("ErrorMessage: {0}", ex.ErrorMessage);
}
You can query the upload progress when uploading an object in streaming, file-based, asynchronous, resumable, or appendable mode, or uploading a part.
Last Article: Performing an Asynchronous Upload
Next Article: Creating a Folder
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.