Single-Connection Bandwidth Limit

Last updated: 2020-09-17 15:48:38

    Overview

    This document describes the bandwidth limit on a single connection when calling the COS APIs for upload or download.

    Samples

    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.

    Sample 1. Single-connection bandwidth limit when uploading

    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);
    
    transferManager.Upload(uploadTask);

    Note:

    For the complete sample, go to GitHub.

    Sample 2. Single-connection bandwidth limit when downloading

    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);
    transferManager.Download(downloadTask);

    Note:

    For the complete sample, go to GitHub.

    Was this page helpful?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help