Overview
This document describes how to limit the speed on a single URL when calling the upload or download API.
Use Instructions
The speed range is 819200 to 838860800 (in bit/s), that is, 100 KB/s to 100 MB/s. If a value is not within this range, 400 will be returned.
Sample 1: limiting single-URL speed on uploads
TransferConfig transferConfig = new TransferConfig();
TransferManager transferManager = new TransferManager(cosXml, transferConfig);
string bucket = "examplebucket-1250000000";
string cosPath = "dir/exampleObject";
string srcPath = @"temp-source-file";
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, cosPath, srcPath);
putObjectRequest.LimitTraffic(8 * 1024 * 1024);
COSXMLUploadTask uploadTask = new COSXMLUploadTask(putObjectRequest);
uploadTask.SetSrcPath(srcPath);
await transferManager.UploadAsync(uploadTask);
Note:
For the complete sample, go to GitHub. Sample 2: limiting single-URL speed on downloads
TransferConfig transferConfig = new TransferConfig();
TransferManager transferManager = new TransferManager(cosXml, transferConfig);
string bucket = "examplebucket-1250000000";
String cosPath = "exampleobject";
string localDir = System.IO.Path.GetTempPath();
string localFileName = "my-local-temp-file";
GetObjectRequest request = new GetObjectRequest(bucket,
cosPath, localDir, localFileName);
request.LimitTraffic(8 * 1024 * 1024);
COSXMLDownloadTask downloadTask = new COSXMLDownloadTask(request);
await transferManager.DownloadAsync(downloadTask);
Note:
For the complete sample, go to GitHub.
Was this page helpful?