tencent cloud

Feedback

Uploading Objects

Last updated: 2022-03-04 11:01:20

    Overview

    This document provides an overview of APIs and SDK code samples related to simple operations and multipart operations.

    Simple operations

    API Operation Description
    PUT Object Uploading an object in whole Uploads an object to a bucket.
    Append Object Appending parts Appends object parts to a bucket.
    POST Object Uploading an object using an HTML form Uploads an object using an HTML form.

    Multipart operations

    API Operation Description
    List Multipart Uploads Querying multipart uploads Queries in-progress multipart uploads.
    Initiate Multipart Upload Initializing a multipart upload Initializes a multipart upload.
    Upload Part Uploading parts Uploads an object in multiple parts.
    List Parts Querying uploaded parts Queries the uploaded parts of a specified multipart upload.
    Complete Multipart Upload Completing a multipart upload Completes the multipart upload of an object.
    Abort Multipart Upload Aborting a multipart upload Aborts a multipart upload and deletes the uploaded parts.

    Simple Operations

    Uploading an object using simple upload

    Description

    This API (PUT Object) is used to upload an object to a bucket. To call this API, you must have write access to the bucket.

    Note:

    • The key (filename) cannot end with /; otherwise, it will be identified as a folder.
    • Each root account (APPID) can have up to 1,000 bucket ACLs and an unlimited number of object ACLs. Do not configure ACLs for an object during upload if you don’t need to control access to it. The object will inherit the permissions of its bucket by default.
    • After an object is uploaded, you can use the same key to generate a pre-signed URL, which can be shared with other clients for downloading. To download, please use the GET method. The detailed API description is shown below. If your file is set to private-read, note that the pre-signed URL will only be valid for a certain period of time.
    • The upload progress onProgress depends on the native xhr.upload.onprogress method. If you find that the upload progress is inaccurate, please check whether a library (such as nuysoft/Mock) that intercepts XHR methods is referenced in your project.

    Sample code

    Uploading a small file:

    cos.putObject({
       Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
       Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
       Key: '1.jpg',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
       StorageClass: 'STANDARD',
       Body: fileObject, // Upload the file object.
       onProgress: function(progressData) {
           console.log(JSON.stringify(progressData));
       }
    }, function(err, data) {
       console.log(err || data);
    });
    

    Uploading a string

    cos.putObject({
       Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
       Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
       Key: '1.txt',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
       Body: 'hello!',
    }, function(err, data) {
       console.log(err || data);
    });
    

    Upload a Base64-encoded string

    var base64Url = 'data:image/png;base64,iVBORw0KGgo.....';
    var dataURLtoBlob = function (dataurl) {
       var arr = dataurl.split(',');
       var mime = arr[0].match(/:(.*?);/)[1];
       var bstr = atob(arr[1]);
       var n = bstr.length;
       var u8arr = new Uint8Array(n);
       while (n--) {
           u8arr[n] = bstr.charCodeAt(n);
       }
       return new Blob([u8arr], { type: mime });
    };
    // Convert to BLOB for upload
    var body = dataURLtoBlob(base64Url);
    cos.putObject({
       Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
       Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
       Key: '1.png',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
       Body: body,
    }, function(err, data) {
       console.log(err || data);
    });
    

    Create directory a:

    cos.putObject({
       Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
       Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
       Key: 'a/',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
       Body: '',
    }, function(err, data) {
       console.log(err || data);
    });
    

    Upload objects to directory a/b:

    cos.putObject({
      Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
      Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
      Key: 'a/b/1.jpg',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
      Body: fileObject, // Upload the file object.
      onProgress: function(progressData) {
          console.log(JSON.stringify(progressData));
      }
    }, function(err, data) {
      console.log(err || data);
    });
    

    Uploading an object (limiting single-URL speed):

    Note:

    For more information about the speed limits on object uploads, please see Single-URL Speed Limits.

    cos.putObject({
       Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
       Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
       Key: '1.jpg',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
       StorageClass: 'STANDARD',
       Body: fileObject, // Upload the file object.
       Headers: {
         'x-cos-traffic-limit': 819200, // The speed range is 819200 to 838860800, that is 100 KB/s to 100 MB/s. If the value is not within this range, 400 will be returned.
       },
       onProgress: function(progressData) {
           console.log(JSON.stringify(progressData));
       }
    }, function(err, data) {
       console.log(err || data);
    });
    

    Parameter description

    Parameter Description Type Required
    Bucket Bucket name in the format of BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, please see Regions and Access Endpoints. String Yes
    Key Object key (object name), the unique identifier of an object in a bucket. For more information, please see Object Overview. String Yes
    Body Content of the file to upload. This parameter can be a file or a BLOB. String\File\Blob Yes
    CacheControl Cache policy as defined in RFC 2616. It will be stored as the object metadata. String No
    ContentDisposition Filename as defined in RFC 2616. It will be stored as the object metadata. String No
    ContentEncoding Encoding format as defined in RFC 2616. It will be stored as the object metadata. String No
    ContentLength HTTP request length (in bytes) as defined in RFC 2616 String No
    ContentType Content type (MIME) as defined in RFC 2616. It will be stored as the object metadata. String No
    Expires Expiration time as defined in RFC 2616. It will be stored as the object metadata. String No
    Expect If Expect: 100-continue is used, the request content will be sent only after confirmation from the server is received. String No
    ACL ACL attribute of the object. For the enumerated values, such as default, private, and public-read, please see the Preset ACL section in ACL Overview.
    Note: if you do not need access control for the object, set this parameter to default or do not specify it, in which case the object will inherit the permissions of the bucket.
    String No
    GrantRead Grants a user read access to the object in the format of id="[OwnerUin]". You can use commas (,) to separate multiple users.
    • To authorize a sub-account, use id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>".
    • To authorize a root account, use id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>".
      Example: 'id="qcs::cam::uin/100000000001:uin/100000000001", id="qcs::cam::uin/100000000001:uin/100000000011"'
    String No
    GrantReadAcp Grants a user read access to the object in the format of id="[OwnerUin]". You can use commas (,) to separate multiple users.
    • To authorize a sub-account, use id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>".
    • To authorize a root account, use id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>".
      Example: 'id="qcs::cam::uin/100000000001:uin/100000000001", id="qcs::cam::uin/100000000001:uin/100000000011"'
    String No
    GrantWriteAcp Grants a user write access to the object in the format of id="[OwnerUin]". You can use commas (,) to separate multiple users.
    • To authorize a sub-account, use id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>".
    • To authorize a root account, use id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>".
      Example: 'id="qcs::cam::uin/100000000001:uin/100000000001", id="qcs::cam::uin/100000000001:uin/100000000011"'
    String No
    GrantFullControl Grants a user full access in the format of id="[OwnerUin]". You can use commas (,) to separate multiple users.
    • To authorize a sub-account, use id="qcs::cam::uin/:uin/<SubUin>".
    • To authorize a root account, use id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>".
      Example: 'id="qcs::cam::uin/100000000001:uin/100000000001", id="qcs::cam::uin/100000000001:uin/100000000011"'
    String No
    StorageClass Storage class of the object. For the enumerated values, such as STANDARD (default), STANDARD_IA, ARCHIVE, and DEEP_ARCHIVE, please see Storage Class Overview. String No
    x-cos-meta-* User-defined headers, which will be saved as the object metadata. The maximum size is 2 KB. String No
    UploadAddMetaMd5 Sets x-cos-meta-md5 as the object’s MD5 checksum in the object's metadata during upload in the format of a 32-bit lowercase string. Example: 4d00d79b6733c9cc066584a02ed03410 String No
    TaskReady Callback function when an upload task is created. The callback returns a taskId, which uniquely identifies the task and can be used to cancel (cancelTask), pause (pauseTask), or resume (restartTask) the task. Function No
    - taskId ID of the upload task String No
    onProgress Progress callback, whose response object is progressData Function No
    - progressData.loaded Size of the uploaded parts, in bytes Number No
    - progressData.total Size of the entire file, in bytes Number No
    - progressData.speed File upload speed, in bytes/s Number No
    - progressData.percent File upload progress, in decimal form. For example, 0.5 means 50% has been uploaded. Number No

    Callback function description

    function(err, data) { ... }
    
    Parameter Description Type
    err Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, please see Error Codes. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    data Content returned when the request is successful. If the request fails, this parameter is empty. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    - ETag MD5 checksum of the object. The value of this parameter can be used to check whether the object was corrupted during the upload.
    Example: "09cba091df696af91549de27b8e7d0f6". Note that double quotation marks are required at the beginning and the end.
    String
    - Location Access address of the uploaded file. String
    - VersionId Version ID of the uploaded object if versioning is enabled for its bucket. If versioning is not enabled, this parameter is not returned. String

    Appending parts

    Description

    This API (APPEND Object) is used to append object parts to a bucket.

    Note:

    • The COS JavaScript SDK should be v1.3.1 or higher.
    • This API only allows appending data to appendable objects.
    • If an object is uploaded using the APPEND Object API for the first time, it will be automatically determined as "appendable".
    • You can use the GET Object or HEAD Object API to get the x-cos-object-type response header to determine the object type.

    Sample code

    Append parts for the first time:

    cos.appendObject({
       Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
       Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
       Key: 'test.txt',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
       Body: fileObject, // Upload the file object.
       Position: 0, // The value is `0` for the first upload.
    }, function(err, data) {
       console.log(err || data);
    });
    

    Check whether parts can be appended for an object in a bucket:

    cos.headObject({
       Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
       Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
       Key: 'test.txt',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
    }, function(err, data) {
       if (err) return console.log(err);
       // If `data.headers` does not contain the `x-cos-object-type` field, you need to configure `expose-headers`. For more information, please see https://intl.cloud.tencent.com/document/product/436/13318?from_cn_redirect=1.
       var objectType = data.headers['x-cos-object-type'];
       console.log(objectType === 'appendable');
    });
    

    Query the position of the object for parts appending and start upload:

    cos.headObject({
       Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
       Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
       Key: 'test.txt',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
    }, function(err, data) {
       if (err) return console.log(err);
       // Get the current length (position for upload) of the file to be appended
       var position = data.headers['content-length'];
       cos.appendObject({
           Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
           Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
           Key: 'test.txt',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
           Body: '66666',
           Position: position,
       },
       function(err, data) {
           if (err) return console.log(err);
           // Get the position for the next upload and continue appending parts
           // If `data.headers` does not contain the `x-cos-next-append-position` field, you need to configure `expose-headers`. For more information, please see https://intl.cloud.tencent.com/document/product/436/13318?from_cn_redirect=1.
           var nextPosition = data.headers['x-cos-next-append-position'];
           console.log(nextPosition);
       })
    });
    

    Parameter description

    Parameter Description Type Required
    Bucket Bucket name in the format of BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, please see Regions and Access Endpoints. String Yes
    Key Object key (object name), the unique identifier of an object in a bucket. For more information, please see Object Overview. String Yes
    Body Content of the file to upload. This parameter can be a file or a BLOB. String\File\Blob Yes
    Position Starting point for the append operation (in bytes). For the first append, the value of this parameter is 0. For subsequent appends, the value is the content-length of the current object. Number Yes
    CacheControl Cache policy as defined in RFC 2616. It will be stored as the object metadata. String No
    ContentDisposition Filename as defined in RFC 2616. It will be stored as the object metadata. String No
    ContentEncoding Encoding format as defined in RFC 2616. It will be stored as the object metadata. String No
    ContentLength HTTP request length (in bytes) as defined in RFC 2616 String No
    ContentType Content type (MIME) as defined in RFC 2616. It will be stored as the object metadata. String No
    Expires Expiration time as defined in RFC 2616. It will be stored as the object metadata. String No
    Expect If Expect: 100-continue is used, the request content will be sent only after confirmation from the server is received. String No
    ACL ACL attribute of the object. For the enumerated values, such as default, private, and public-read, please see the Preset ACL section in ACL Overview.
    Note: if you do not need access control for the object, set this parameter to default or do not specify it, in which case the object will inherit the permissions of the bucket.
    String No
    GrantRead Grants a user read access to the object in the format of id="[OwnerUin]". You can use commas (,) to separate multiple users.
    • To authorize a sub-account, use id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>".
    • To authorize a root account, use id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>".
      Example: 'id="qcs::cam::uin/100000000001:uin/100000000001", id="qcs::cam::uin/100000000001:uin/100000000011"'
    String No
    GrantReadAcp Grants a user read access to the object in the format of id="[OwnerUin]". You can use commas (,) to separate multiple users.
    • To authorize a sub-account, use id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>".
    • To authorize a root account, use id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>".
      Example: 'id="qcs::cam::uin/100000000001:uin/100000000001", id="qcs::cam::uin/100000000001:uin/100000000011"'
    String No
    GrantWriteAcp Grants a user write access to the object in the format of id="[OwnerUin]". You can use commas (,) to separate multiple users.
    • To authorize a sub-account, use id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>".
    • To authorize a root account, use id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>".
      Example: 'id="qcs::cam::uin/100000000001:uin/100000000001", id="qcs::cam::uin/100000000001:uin/100000000011"'
    String No
    GrantFullControl Grants a user full access in the format of id="[OwnerUin]". You can use commas (,) to separate multiple users.
    • To authorize a sub-account, use id="qcs::cam::uin/:uin/<SubUin>".
    • To authorize a root account, use id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>".
      Example: 'id="qcs::cam::uin/100000000001:uin/100000000001", id="qcs::cam::uin/100000000001:uin/100000000011"'
    String No
    StorageClass Storage class of the object. For the enumerated values, such as STANDARD (default), STANDARD_IA, ARCHIVE, and DEEP_ARCHIVE, please see Storage Class Overview. String No
    x-cos-meta-* User-defined headers, which will be saved as the object metadata. The maximum size is 2 KB. String No

    Callback function description

    function(err, data) { ... }
    
    Parameter Description Type
    err Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, please see Error Codes. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    data Content returned when the request is successful. If the request fails, this parameter is empty. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    - RequestId Unique ID of the request String

    Uploading an object using an HTML form

    The SDK for JS does not provide a method for the POST Object API. If you need to use this API, please see "Solution B: Upload with Form" in Practice of Direct Transfer for Web End.

    Multipart Operations

    Querying multipart uploads

    Description

    This API (List Multipart Uploads) is used to query in-progress multipart uploads. Up to 1,000 multipart uploads can be listed at a time.

    Sample code

    Get the list of incomplete multipart uploads whose UploadId is prefixed with a:

    cos.multipartList({
       Bucket: 'examplebucket-1250000000', /* Required */
       Region: 'COS_REGION',     /* Bucket region. Required */
       Prefix: 'a',                        /* Optional */
    }, function(err, data) {
       console.log(err || data);
    });
    

    Parameter description

    Parameter Description Type Required
    Bucket Bucket name in the format of BucketName-APPID. String Yes
    Region Bucket region. For the enumerated values, please see Regions and Access Endpoints. String Yes
    Prefix Object key prefix to query uploads by. Note that when you query uploads with the prefix specified, the returned object keys will also contain the prefix. String No
    Delimiter Separating symbol used to group object keys, which is usually /. Objects with identical paths between Prefix or, if no Prefix is specified, the beginning of their keys, and the first delimiter are grouped together and defined as common prefixes. All common prefixes are listed. String No
    EncodingType Encoding type of the returned value. Valid value: url String No
    MaxUploads Maximum number of entries to return at a time. Valid range: 1-1000 (default) String No
    KeyMarker This parameter is used together with upload-id-marker.
      If upload-id-marker is not specified:
       - Only multipart uploads whose ObjectName is lexicographically greater than the specified key-marker will be listed.
    • If upload-id-marker is specified:
       - Multipart uploads whose ObjectName is lexicographically greater than the specified key-marker will be listed;
       - Multipart uploads whose ObjectName is lexicographically equal to the specified key-marker and whose UploadID is greater than the specified upload-id-marker will be listed.
    String No
    UploadIdMarker This parameter is used together with key-marker.
    • If key-marker is not specified:
       - upload-id-marker will be ignored.
    • If key-marker is specified:
       - Multipart uploads whose ObjectName is lexicographically greater than the specified key-marker will be listed;
       - Multipart uploads whose ObjectName is lexicographically equal to the specified key-marker and whose UploadID is greater than the specified upload-id-marker will be listed.
    String No

    Callback function description

    function(err, data) { ... }
    
    Parameter                                Description Type
    err Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, please see Error Codes. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    data Content returned when the request is successful. If the request fails, this parameter is empty. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    - Bucket Destination bucket for the multipart upload String
    - Encoding-Type Encoding type of the returned value. Valid value: url String
    - KeyMarker The key after which the returned listing begins String
    - UploadIdMarker The UploadId after which the returned list begins String
    - NextKeyMarker The key after which the next returned list begins if the list is truncated String
    - NextUploadIdMarker The UploadId after which the next returned list begins if the list is truncated String
    - MaxUploads The maximum number of returned entries. Valid value range: 1-1000 String
    - IsTruncated Whether the returned list is truncated. Valid value: true; false String
    - Prefix Object key prefix by which uploads are queried String
    Delimiter Separating symbol used to group object keys, which is usually /. Objects with identical paths between Prefix or, if no Prefix is specified, the beginning of their keys, and the first delimiter are grouped together and defined as common prefixes. All common prefixes are listed. String
    - CommonPrefixs Objects with identical paths between Prefix and the delimiter, which are grouped together and defined as common prefixes ObjectArray
    - - Prefix Specific prefixes String
    - Upload Information of the multipart uploads ObjectArray
    - - Key Name of the object, i.e. object key String
    - - UploadId ID of the multipart upload String
    - - StorageClass Storage class of the parts. For the enumerated values, such as STANDARD, STANDARD_IA, ARCHIVE, and DEEP_ARCHIVE, please see Storage Class Overview. String
    - - Initiator Initiator of the multipart upload Object
    - - - DisplayName Name of the upload initiator String
    - - - ID ID of the upload initiator in the format of qcs::cam::uin/<owneruin>:uin/<subuin>
    For root accounts, <OwnerUin> and <SubUin> have the same value.
    String
    - - Owner Owner of the parts Object
    - - - DisplayName Name of the part owner String
    - - - ID ID of the parts owner in the format of qcs::cam::uin/<owneruin>:uin/<subuin>.
    For root accounts, <OwnerUin> and <SubUin> have the same value.
    String
    - - Initiated Start time of the multipart upload String

    Initializing a multipart upload

    Description

    This API (Initiate Multipart Upload) is used to initialize a multipart upload. After a successful initialization operation, an upload ID will be returned, which is required for the subsequent Upload Part request.

    Sample code

    cos.multipartInit({
       Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
       Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
       Key: '1.jpg',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
       UploadId: 'exampleUploadId',
       Body: fileObject
    }, function(err, data) {
       console.log(err || data);
       if (data) {
         uploadId = data.UploadId;
       }
    });
    

    Parameter description

    Parameter Description Type Required
    Bucket Bucket name in the format of BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, please see Regions and Access Endpoints. String Yes
    Key Object key (object name), the unique identifier of an object in a bucket. For more information, please see Object Overview. String Yes
    CacheControl Cache policy as defined in RFC 2616. It will be stored as the object metadata. String No
    Content-Disposition Filename as defined in RFC 2616. It will be stored as the object metadata. String No
    ContentEncoding Encoding format as defined in RFC 2616. It will be stored as the object metadata. String No
    ContentType Content type (MIME) as defined in RFC 2616. It will be stored as the object metadata. String No
    Expires Cache expiration time as defined in RFC 2616. It will be stored as the object metadata. String No
    ACL ACL attribute of the object. For the enumerated values, such as default, private, and public-read, please see the Preset ACL section in ACL Overview.
    Note: If you do not need access control for the object, set this parameter to default or do not specify it, in which case the object will inherit the permissions of its bucket.
    String No
    GrantRead Grants a user read access to the object in the format of id="[OwnerUin]". You can use commas (,) to separate multiple users.
    • To authorize a sub-account, use id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>".
    • To authorize a root account, use id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>".
      Example: 'id="qcs::cam::uin/100000000001:uin/100000000001", id="qcs::cam::uin/100000000001:uin/100000000011"'
    String No
    GrantFullControl Grants a user full access in the format of id="[OwnerUin]". You can use commas (,) to separate multiple users.
    • To authorize a sub-account, use id="qcs::cam::uin/<OwnerUin>:uin/<SubUin>".
    • To authorize a root account, use id="qcs::cam::uin/<OwnerUin>:uin/<OwnerUin>".
      Example: 'id="qcs::cam::uin/100000000001:uin/100000000001", id="qcs::cam::uin/100000000001:uin/100000000011"'
    String No
    StorageClass Storage class of the object. For the enumerated values, such as STANDARD (default), STANDARD_IA, ARCHIVE, and DEEP_ARCHIVE, please see Storage Class Overview. String No
    x-cos-meta-* User-defined headers, which will be returned as the object metadata. The maximum size is 2 KB. String No
    UploadAddMetaMd5 Sets x-cos-meta-md5 as the object’s MD5 checksum in the object’s metadata during upload in the format of a 32-bit lowercase string. Example: 4d00d79b6733c9cc066584a02ed03410 String No

    Callback function description

    function(err, data) { ... }
    
    Parameter Description Type
    err Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, please see Error Codes. Object
    data Content returned when the request is successful. If the request fails, this parameter is empty. Object
    Bucket Name of the destination bucket for the multipart upload. The value is formed by connecting a user-defined string and the system-generated APPID with a hyphen, for example, examplebucket-1250000000. string
    Key Object key (object name), the unique identifier of an object in a bucket. For more information, please see Object Overview. String
    UploadId Upload ID, which is required for the subsequent upload String

    Uploading parts

    Description

    This API (Upload Part) is used to upload parts after a multipart upload is initialized. It can upload 1-10,000 parts of 1 MB to 5 GB at a time.

    • After calling the Initiate Multipart Upload API to initialize a multipart upload, you will get an upload ID. This ID uniquely identifies the part and marks its position in the object.
    • Every time you call the Upload Part API, you need to pass in partNumber (the part number) and uploadId. You can upload multiple parts out of order.
    • When the uploadId and partNumber of a new part are the same as those of a previously uploaded part, the old part will be overwritten. If the uploadId does not exist, 404 (NoSuchUpload) will be returned.

    Sample code

    cos.multipartUpload({
       Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
       Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
       Key: '1.jpg',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
       UploadId: 'exampleUploadId',
       PartNumber: 1,
       Body: fileObject
    }, function(err, data) {
       console.log(err || data);
       if (data) {
         eTag = data.ETag;
       }
    });
    

    Parameter description

    Parameter Description Type Required
    Bucket Bucket name in the format of BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, please see Regions and Access Endpoints. String Yes
    Key Object key (object name), the unique identifier of an object in a bucket. For more information, please see Object Overview. String Yes
    ContentLength HTTP request length (in bytes) as defined in RFC 2616 String Yes
    PartNumber Part number Number Yes
    UploadId ID of the multipart upload String Yes
    Body Content of the part to upload This parameter can be a file or a BLOB. String\File\Blob Yes
    Expect HTTP request length (in bytes) defined in RFC 2616. If Expect: 100-continue is used, the request content will be sent only after confirmation from the server is received. String No
    ContentMD5 Base64-encoded 128-bit MD5 checksum as defined in RFC 1864. This header is used to verify whether the file content has changed. String No

    Callback function description

    function(err, data) { ... }
    
    Parameter Description Type
    err Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, please see Error Codes. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    data Content returned when the request is successful. If the request fails, this parameter is empty. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object

    Querying uploaded parts

    Description

    This API (List Parts) is used to query the uploaded parts of a specified multipart upload, i.e., listing all successfully uploaded parts of a multipart upload with the specified uploadId.

    Sample code

    cos.multipartListPart({
       Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
       Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
       Key: '1.jpg',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
       UploadId: 'exampleUploadId', /*Required*/
    }, function(err, data) {
       console.log(err || data);
    });
    

    Parameter description

    Parameter Description Type Required
    Bucket Bucket name in the format of BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, please see Regions and Access Endpoints. String Yes
    Key Object key (object name), the unique identifier of an object in a bucket. For more information, please see Object Overview. String Yes
    UploadId Multipart upload ID, which is obtained from the response of the Initiate Multipart Upload API String Yes
    EncodingType Encoding type of the returned value String No
    max-parts Maximum number of parts to return at a time. Default: 1000 string No
    PartNumberMarker The marker after which the returned list begins. By default, entries are listed in UTF-8 binary order. String No

    Callback function description

    function(err, data) { ... }
    
    Parameter                                       Description Type
    err Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, please see Error Codes. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    data Content returned when the request is successful. If the request fails, this parameter is empty. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    - Bucket Destination bucket for the multipart upload String
    EncodingType Encoding type of the returned value String
    - Key Object key (object name), the unique identifier of an object in a bucket. For more information, please see Object Overview. String
    - UploadId ID of the multipart upload String
    - Initiator Initiator of the multipart upload Object
    - - DisplayName Name of the upload initiator String
    - - - ID ID of the upload initiator in the format of qcs::cam::uin/<owneruin>:uin/<subuin>.
    For root accounts, <OwnerUin> and <SubUin> have the same value.
    String
    - Owner Owner of the parts Object
    - - DisplayName Name of the bucket owner String
    - - ID Bucket owner ID, generally the user's UIN String
    - StorageClass Storage class of the parts. For the enumerated values, such as STANDARD, STANDARD_IA, ARCHIVE, and DEEP_ARCHIVE, please see Storage Classes Overview. String
    - PartNumberMarker The marker after which the returned list begins. By default, entries are listed in UTF-8 binary order. String
    NextPartNumberMarker The part after which the next returned list begins if the list is truncated String
    - MaxUploads The maximum number of entries returned in a single request String
    - IsTruncated Whether the returned list is truncated. Valid value: true; false String
    - Part Parts information list ObjectArray
    - - PartNumber Part number String
    - - LastModified Last modified time of the part String
    - - ETag MD5 algorithm checksum of the part String
    - - Size Part size, in bytes String

    Completing a multipart upload

    Description

    This API (Complete Multipart Upload) is used to complete a multipart upload. After all parts are uploaded via the Upload Part API, you need to call this API to complete the multipart upload. When using this API, you need to specify the PartNumber and ETag of each part in the request body for the part information to be verified.
    The parts need to be reassembled after they are uploaded, which takes several minutes. When the assembly starts, COS will immediately return the status code 200 and will periodically return spaces during the process to keep the connection active until the assembly is completed. After that, COS will return the assembled result in the body.

    • If any uploaded part is less than 1 MB in size, 400 (EntityTooSmall) will be returned when this API is called.
    • If the part numbers are not continuous, "400 InvalidPart" will be returned when this API is called.
    • If the part numbers in the request body are not in ascending order, "400 InvalidPartOrder" will be returned when this API is called.
    • If the uploadId does not exist, 404 (NoSuchUpload) will be returned when this API is called.
    Note:

    We recommend you either complete or abort a multipart upload as early as possible, as the uploaded parts of an incomplete multipart upload will take up storage capacity and incur storage fees.

    Sample code

    cos.multipartComplete({
       Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
       Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
       Key: '1.jpg',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
       UploadId: 'exampleUploadId', /*Required*/
       Parts: [
           {PartNumber: 1, ETag: 'exampleETag'},
       ]
    }, function(err, data) {
       console.log(err || data);
    });
    

    Parameter description

    Parameter Description Type Required
    Bucket Bucket name in the format of BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, please see Regions and Access Endpoints. String Yes
    Key Object key (object name), the unique identifier of an object in a bucket. For more information, please see Object Overview. String Yes
    UploadId ID of the upload String Yes
    Parts A list of information about the parts of the multipart upload ObjectArray Yes
    - PartNumber Part number Number Yes
    - ETag MD5 checksum of each part.
    Example: "22ca88419e2ed4721c23807c678adbe4c08a7880"
    Note that double quotation marks are required at the beginning and the end.
    String Yes

    Callback function description

    function(err, data) { ... }
    
    Parameter Description Type
    err Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, please see Error Codes. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    data Content returned when the request is successful. If the request fails, this parameter is empty. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    - Location Access address of the uploaded file. String
    - Bucket Destination bucket for the multipart upload String
    - Key Object key (object name), the unique identifier of an object in a bucket. For more information, please see Object Overview. String
    - ETag Unique ID of the file after assembly in the format of "uuid-<part quantity="">".
    Example: "22ca88419e2ed4721c23807c678adbe4c08a7880-3". Note that double quotation marks are required at the beginning and the end.
    String

    Aborting a multipart upload

    Description

    This API (Abort Multipart Upload) is used to abort a multipart upload and delete the uploaded parts. If you call this API and there is an in-progress upload request with the specified UploadId, the upload request will fail. If the uploadId does not exist, 404 (NoSuchUpload) will be returned.

    Note:

    We recommend you either complete or abort a multipart upload as early as possible, as the uploaded parts of an incomplete multipart upload will take up storage capacity and incur storage fees.

    Sample code

    cos.multipartAbort({
       Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
       Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
       Key: '1.jpg',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
       UploadId: 'exampleUploadId' /*Required*/
    }, function(err, data) {
       console.log(err || data);
    });
    

    Parameter description

    Parameter Description Type Required
    Bucket Bucket name in the format of BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, please see Regions and Access Endpoints. String Yes
    Key Object key (object name), the unique identifier of an object in a bucket. For more information, please see Object Overview. String Yes
    UploadId Multipart upload ID, which is obtained from the response of the Initiate Multipart Upload API String Yes

    Callback function description

    function(err, data) { ... }
    
    Parameter Description Type
    err Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, please see Error Codes. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    data Content returned when the request is successful. If the request fails, this parameter is empty. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object

    Advanced APIs (Recommended)

    We strongly recommend you use advanced APIs, which encapsulate the native methods mentioned above. They can implement the complete process of multipart upload and support concurrent multipart upload, checkpoint restart as well as canceling, pausing, and resuming upload tasks.

    Advanced upload

    Description

    This API is used to implement an advanced upload. You can use the SliceSize parameter to specify a file size threshold (1 MB by default). If a file is larger than this threshold, it will be uploaded in parts; otherwise, it will be uploaded in whole.

    Sample code

    cos.uploadFile({
       Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
       Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
       Key: '1.jpg',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
       Body: fileObject,               /*Required*/
       SliceSize: 1024 * 1024 * 5,     /* Threshold (5 MB in this example) to trigger multipart upload. Optional */
       TaskReady: function(taskId) { /*Optional*/
           console.log(taskId);
       },
       onProgress: function (progressData) { /* Optional */
           console.log(JSON.stringify(progressData));
       },
       onFileFinish: function (err, data, options) { /* Optional */
          console.log(options.Key + 'upload' + (err ? 'failed' : 'completed'));
       },
    }, function(err, data) {
       console.log(err || data);
    });
    

    Parameter description

    Parameter Description Type Required
    Bucket Bucket name in the format of BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, please see Regions and Access Endpoints. String Yes
    Key Object key (object name), the unique identifier of an object in a bucket. For more information, please see Object Overview. String Yes
    Body Content of the file to upload, which can be a file or a BLOB File\Blob Yes
    SliceSize File size threshold in bytes, 1048576 (1 MB) by default. If the file size is equal to or smaller than this value, the file will be uploaded using putObject; otherwise, it will be uploaded using sliceUploadFile. Number No
    AsyncLimit Maximum number of concurrently uploaded parts allowed. This parameter is valid only when a multipart upload is triggered. Number No
    StorageClass Storage class of the object, such as STANDARD, STANDARD_IA, ARCHIVE, and DEEP_ARCHIVE. For more information, please see Storage Class Overview. String No
    UploadAddMetaMd5 Sets x-cos-meta-md5 as the object’s MD5 checksum in the object’s metadata during upload in the format of a 32-bit lowercase string. Example: 4d00d79b6733c9cc066584a02ed03410. String No
    onTaskReady Callback function when an upload task is created. The callback returns a taskId, which uniquely identifies the task and can be used to cancel (cancelTask), pause (pauseTask), or resume (restartTask) the task. Function No
    - taskId ID of the upload task String No
    onProgress Callback for the upload progress, whose parameter is progressData Function No
    - progressData.loaded Size of the uploaded parts, in bytes Number No
    - progressData.total Size of the entire file, in bytes Number No
    - progressData.speed File upload speed, in bytes/s Number No
    - progressData.percent File upload progress, in decimal form. For example, 0.5 means 50% has been uploaded. Number No
    onFileFinish Completion or error callback for each file Function No
    - err Upload error message Object No
    - data Information about the completion of object upload Object No
    - options Parameter information about the files that have been uploaded Object No

    Callback function description

    function(err, data) { ... }
    
    Parameter Description Type
    err Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, please see Error Codes. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    data Content returned when the request is successful. If the request fails, this parameter is empty. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    - Location Access address of the uploaded file. String
    - Bucket Destination bucket for the multipart upload. This parameter is returned only when a multipart upload is triggered. String
    - Key Object key (object name), the unique identifier of an object in a bucket. For more information, see Object Overview > Object Key. This parameter is returned only when multipart upload is triggered. String
    - ETag Unique ID of the file after assembly in the format of "uuid-<part quantity="">".
    Example: "22ca88419e2ed4721c23807c678adbe4c08a7880-3". Note that double quotation marks are required at the beginning and the end.
    String
    - VersionId Version ID of the uploaded object if versioning is enabled for its bucket. If versioning is not enabled, this parameter is not returned. String

    Uploading an object using multipart upload (checkpoint restart)

    Description

    This API (Slice Upload File) is used to upload large files in parts.

    Note:

    • If the browser is not closed, you can pause, resume, or cancel an upload.
    • If you upload the same file to the same bucket path after refreshing the browser, the file content will be verified based on UploadId and the upload will proceed if the verification is passed.

    Sample code

    cos.sliceUploadFile({
       Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
       Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
       Key: '1.jpg',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
       Body: fileObject,               /*Required*/
       TaskReady: function(taskId) { /*Optional*/
           console.log(taskId);
       },
       onHashProgress: function (progressData) { /* Optional */
           console.log(JSON.stringify(progressData));
       },
       onProgress: function (progressData) { /* Optional */
           console.log(JSON.stringify(progressData));
       }
    }, function(err, data) {
       console.log(err || data);
    });
    

    Parameter description

    Parameter                                  Description Type Required
    Bucket Bucket name in the format of BucketName-APPID String Yes
    Region Bucket region. For the enumerated values, please see Regions and Access Endpoints. String Yes
    Key Object key (object name), the unique identifier of an object in a bucket. For more information, please see Object Overview. String Yes
    Body Content of the file to upload, which can be a file or a BLOB File\Blob Yes
    SliceSize Part size Number No
    AsyncLimit Maximum number of concurrently uploaded parts allowed String No
    StorageClass Storage class of the object, such as STANDARD, STANDARD_IA, ARCHIVE, and DEEP_ARCHIVE. For more information, please see Storage Class Overview. String No
    UploadAddMetaMd5 Sets x-cos-meta-md5 as the object’s MD5 checksum in the object’s metadata during upload in the format of a 32-bit lowercase string. Example: 4d00d79b6733c9cc066584a02ed03410. String No
    onTaskReady Callback function when an upload task is created. The callback returns a taskId, which uniquely identifies the task and can be used to cancel (cancelTask), pause (pauseTask), or resume (restartTask) the task. Function No
    - taskId ID of the upload task String No
    onHashProgress Callback for the progress of MD5 checksum calculation, whose parameter is progressData Function No
    - progressData.loaded Size of the verified parts, in bytes Number No
    - progressData.total Size of the entire file, in bytes Number No
    - progressData.speed File verification speed in bytes/s Number No
    - progressData.percent Percentage of the file verification progress, in decimal form. For example, 0.5 means 50% has been verified. Number No
    onProgress Callback for the upload progress, whose parameter is progressData Function No
    - progressData.loaded Size of the uploaded parts, in bytes Number No
    - progressData.total Size of the entire file, in bytes Number No
    - progressData.speed File upload speed, in bytes/s Number No
    - progressData.percent File upload progress, in decimal form. For example, 0.5 means 50% has been uploaded. Number No

    Callback function description

    function(err, data) { ... }
    
    Parameter Description Type
    err Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, please see Error Codes. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    data Content returned when the request is successful. If the request fails, this parameter is empty. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    - Location Access address of the uploaded file. String
    - Bucket Destination bucket for the multipart upload String
    - Key Object key (object name), the unique identifier of an object in a bucket. For more information, please see Object Overview. String
    - ETag Unique ID of the file after assembly in the format of "uuid-<part quantity="">".
    Example: "22ca88419e2ed4721c23807c678adbe4c08a7880-3". Note that double quotation marks are required at the beginning and the end.
    String
    - VersionId Version ID of the uploaded object if versioning is enabled for its bucket. If versioning is not enabled, this parameter is not returned. String

    Batch upload

    Description

    Method 1:
    You can call putObject or sliceUploadFile multiple times to implement batch uploads. Instantiate the FileParallelLimit parameter to limit the maximum number (default value: 3) of concurrently uploaded files allowed.

    Method 2:
    You can also call cos.uploadFiles to implement batch uploads. The SliceSize parameter can be used to determine whether to use sliceUploadFile. See below for how to use the uploadFiles method.

    Method prototype

    Calling uploadFiles

    cos.uploadFiles({
       files: [{
           Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
           Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
           Key: '1.jpg',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
           Body: fileObject1,
           onTaskReady: function(taskId) {
             /* Based on `taskId`, you can use queue operations to cancel upload `cos.cancelTask(taskId)`, pause upload `cos.pauseTask(taskId)`, and resume upload `cos.restartTask(taskId)` */
             console.log(taskId);
           }
       }, {
           Bucket: 'examplebucket-1250000000', /* Your bucket name. Required. */
           Region: 'COS_REGION',  /* Bucket region, such as `ap-beijing`. Required. */
           Key: '2.jpg',  /* Object key stored in the bucket (such as `1.jpg` and `a/b/test.txt`). Required. */
           Body: fileObject2,
           onTaskReady: function(taskId) {
           /* Based on `taskId`, you can use queue operations to cancel upload `cos.cancelTask(taskId)`, pause upload `cos.pauseTask(taskId)`, and resume upload `cos.restartTask(taskId)` */
           console.log(taskId);
         }
       }],
       SliceSize: 1024 * 1024 * 10,    /* Set the file size threshold to trigger a multipart upload to 10 MB */
       onProgress: function (info) {
           var percent = parseInt(info.percent * 10000) / 100;
           var speed = parseInt(info.speed / 1024 / 1024 * 100) / 100;
           console.log('progress:' + percent + '%; speed:' + speed + 'Mb/s;');
       },
       onFileFinish: function (err, data, options) { 
           console.log(options.Key + 'upload' + (err ? 'failed' : 'completed'));
       },
    }, function (err, data) {
       console.log(err || data);
    });
    

    Parameter description

    Parameter Description Type Required
    files File list. Each item is a parameter object to be passed to putObject and sliceUploadFile. Object Yes
    - Bucket Bucket name in the format of BucketName-APPID. String Yes
    - Region Bucket region. For the enumerated values, please see Regions and Access Endpoints. String Yes
    - Key Object key (object name), the unique identifier of an object in a bucket. For more information, please see Object Overview. String Yes
    - Body Content of the file to upload, which can be a file or a BLOB File\Blob Yes
    - onTaskReady Callback function when an upload task is created. The callback returns a taskId, which uniquely identifies the task and can be used to cancel (cancelTask), pause (pauseTask), or resume (restartTask) the task. Function No
    -- taskId ID of the upload task String No
    SliceSize File size threshold in bytes, 1048576 (1 MB) by default. If the file size is equal to or smaller than this value, it will be uploaded using putObject; otherwise, it will be uploaded using sliceUploadFile. Number Yes
    AsyncLimit Maximum number of concurrently uploaded parts allowed. This parameter is valid only when a multipart upload is triggered. Number No
    onProgress Upload progress calculated by averaging out the progress of all tasks String Yes
    - progressData.loaded Size of the uploaded parts, in bytes Number No
    - progressData.total Size of the entire file, in bytes Number No
    - progressData.speed File upload speed, in bytes/s Number No
    - progressData.percent File upload progress, in decimal form. For example, 0.5 means 50% has been uploaded. Number No
    onFileFinish Completion or error callback for each file Function No
    - err Upload error message Object No
    - data Information about the completion of object upload Object No
    - options Parameter information about the files that have been uploaded Object No

    Callback function description

    function(err, data) { ... }
    
    Parameter Description Type
    err Error code, which is returned when an error (network error or service error) occurs. If the request is successful, this parameter is empty. For more information, please see Error Codes. Object
    - statusCode HTTP status code, such as 200, 403, and 404 Number
    - headers Headers Object
    data Content returned when the request is successful. If the request fails, this parameter is empty. Object
    - files Error or data for each file ObjectArray
    - - error Upload error message Object
    - - data Information about the completion of object upload Object
    - - options Parameter information about the files that have been uploaded Object

    Uploading queue

    The SDK for JavaScript records all the upload tasks initiated with putObject and sliceUploadFile in an upload queue. You can use the queue in the following ways:

    1. Use cos.getTaskList to get the task list.
    2. Use cos.pauseTask, cos.restartTask, and cos.cancelTask to perform operations on upload tasks.
    3. Use cos.on('list-update', callback); to listen for list and progress changes.

    For detailed instructions on how to use the upload queue, please see Queue Demo.

    Canceling an upload task

    This API is used to cancel an upload task by taskId.

    Example

    var taskId = 'xxxxx';                   /* Required */
    cos.cancelTask(taskId);
    

    Parameter description

    Parameter Description Type Required
    taskId ID of the upload task. When sliceUploadFile is called, the taskId is returned via the TaskReadycallback. String Yes

    Suspending an upload task

    This API is used to pause an upload task by taskId.

    Example

    var taskId = 'xxxxx';                   /* Required */
    cos.pauseTask(taskId);
    

    Parameter description

    Parameter Description Type Required
    taskId ID of the upload task. When sliceUploadFile is called, the taskId is returned via the TaskReadycallback. String Yes

    Resuming an upload task

    This API is used to resume an upload task by taskId. You can resume tasks that have been manually paused through the pauseTask API, or automatically paused due to an upload error.

    Example

    var taskId = 'xxxxx';                   /* Required */
    cos.restartTask(taskId);
    

    Parameter description

    ParameterDescriptionTypeRequired
    taskIdID of the upload task. When `sliceUploadFile` is called, the `taskId` is returned via the `TaskReady` callback.StringYes
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support