This document describes the bandwidth limit on a single connection when calling the COS APIs for upload or download.
This limit should have a value in bit/s ranging from 819200 - 838860800, i.e. 100 KB/s - 100 MB/s. If this range is exceeded, a 400 error will be returned.
TransferConfig transferConfig = new TransferConfig();
// Initialize TransferManager
TransferManager transferManager = new TransferManager(cosXml, transferConfig);
string bucket = "examplebucket-1250000000"; // Bucket name in the format of BucketName-APPID
string cosPath = "dir/exampleObject"; // Object key
string srcPath = @"temp-source-file";// Absolute path to the local file
PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, cosPath, srcPath);
putObjectRequest.LimitTraffic(8 * 1000 * 1000); // Set the limit to 1 MB/s
COSXMLUploadTask uploadTask = new COSXMLUploadTask(putObjectRequest);
uploadTask.SetSrcPath(srcPath);
await transferManager.UploadAsync(uploadTask);
Note:
For the complete sample, go to GitHub.
TransferConfig transferConfig = new TransferConfig();
// Initialize TransferManager
TransferManager transferManager = new TransferManager(cosXml, transferConfig);
String bucket = "examplebucket-1250000000"; // Bucket name in the format: BucketName-APPID
String cosPath = "exampleobject"; // The location identifier of the object in the bucket, i.e. the object key
string localDir = System.IO.Path.GetTempPath();// Local file directory
string localFileName = "my-local-temp-file"; // Specify the name of the file to be saved locally
GetObjectRequest request = new GetObjectRequest(bucket,
cosPath, localDir, localFileName);
request.LimitTraffic(8 * 1000 * 1024); // Set the limit to 1 MB/s
COSXMLDownloadTask downloadTask = new COSXMLDownloadTask(request);
await transferManager.DownloadAsync(downloadTask);
Note:
For the complete sample, go to GitHub.
Was this page helpful?