Updated on 2022-02-10 GMT+08:00

Append Object

API Description

You can use this API to upload an object in appendable mode and append data to the object.

Method Definition

ObsClient.appendObject

Request Parameter

Field

Type

Optional or Mandatory

Description

Bucket

String

Mandatory

Bucket name

Key

String

Mandatory

Object name

RequestDate

String

or

Date

Optional

Request time

NOTE:

When the parameter type is String, the value must comply with the ISO8601 or RFC822 standards.

Position

Number

Mandatory

Start position for next appending. This parameter must be set to 0 when you create an appendable object.

ACL

String

Optional

Pre-defined access control policy specified during object creation

StorageClass

String

Optional

Storage class, which can be specified during the object creation

Body

String

Optional

Object content to be uploaded

SourceFile

File

or

Blob

Optional

File to be uploaded (The browser must support FileReader.)

ProgressCallback

Function

Optional

Callback function for obtaining the upload progress

NOTE:

This callback function contains the following parameters in sequence: Number of uploaded bytes, total bytes, and used time (unit: second).

Offset

Number

Optional

Start offset (in bytes) of a part in the source file. The default value is 0. This field is effective only when SourceFile is set.

Metadata

Object

Optional

Customized metadata of the object

WebsiteRedirectLocation

String

Optional

Location where the object is redirected to, when the bucket is configured with website hosting

Expires

Number

Optional

Expiration time of the object, in days

SuccessActionRedirect

String

Optional

Redirection address after the upload is successful

ContentType

String

Optional

MIME type of the object

ContentLength

Number

Optional

Object size in bytes. This parameter is effective when SourceFile is set.

ContentMD5

String

Optional

Base64-encoded MD5 value of the object data to be uploaded. It is provided for the OBS server to verify data integrity.

SseKms

String

Optional

Algorithm used in SSE-KMS encryption. The value can be:

  • kms

SseKmsKey

String

Optional

Master key used in SSE-KMS encryption. The value can be null.

SseC

String

Optional

Algorithm used in SSE-C encryption. The value can be:

  • AES256

SseCKey

Buffer

Optional

Key used in SSE-C encryption. It is calculated by using AES-256.

  • Body and SourceFile cannot be used together.
  • If both Body and SourceFile are null, the size of the object to be uploaded is 0 bytes.

Returned Result (InterfaceResult)

Field

Type

Description

RequestId

String

Request ID returned by the OBS server

ETag

String

Object ETag

NextPosition

String

Start position for next appending

StorageClass

String

Storage class of the object. When the storage class is OBS Standard, the value is null.

Sample Code

obsClient.appendObject({
       Bucket : 'bucketname',
       Key : 'objectkey',
//     SourceFile : 'localfile',
       Body : 'Hello OBS',
       Position: 0
}, function (err, result) {
       if(err){
              console.error('Error-->' + err);
       }else{
              if(result.CommonMsg.Status < 300){
                     console.log('RequestId-->' + result.InterfaceResult.RequestId);
                     console.log('ETag-->' + result.InterfaceResult.ETag);
                     console.log('NextPosition-->' + result.InterfaceResult.NextPosition);
              }else{
                     console.log('Code-->' + result.CommonMsg.Code);
                     console.log('Message-->' + result.CommonMsg.Message);
              }
       }
});