All Products
Search
Document Center

Object Storage Service:Node.js append upload

Last Updated:Sep 17, 2025

You can call the AppendObject operation to append content to existing appendable objects.

Usage notes

  • In this topic, the public endpoint of the China (Hangzhou) region is used. To access OSS from other Alibaba Cloud services in the same region, use an internal endpoint. For details about supported regions and endpoints, see Regions and endpoints.

  • In this topic, access credentials are obtained from environment variables. For more information about how to configure access credentials, see Configure access credentials.

  • In this topic, an OSSClient instance is created by using an OSS endpoint. If you want to create an OSSClient instance by using custom domain names or Security Token Service (STS), see Configuration examples for common scenarios.

  • If the object to which you want to append content does not exist, the AppendObject operation creates an appendable object.

  • If the object to which you want to append content exists:

    • If the object is an appendable object and the specified position from which the append operation starts is equal to the current object size, the data is appended to the end of the object.

    • If the object is an appendable object and the specified position from which the append operation starts is not equal to the current object size, the PositionNotEqualToLength error is returned.

    • If the object is not an appendable object, the ObjectNotAppendable error is returned.

Permissions

By default, an Alibaba Cloud account has full permissions. RAM users or RAM roles under an Alibaba Cloud account do not have any permissions by default. The Alibaba Cloud account or account administrator must grant operation permissions through RAM Policy or Bucket Policy.

API

Action

Definition

AppendObject

oss:PutObject

You can call this operation to upload an object by appending the object to an existing object.

oss:PutObjectTagging

When uploading an object by appending the object to an existing object, if you specify object tags through x-oss-tagging, this permission is required.

Sample code

The following code shows how to perform an append upload:

const OSS = require('ali-oss')

const client = new OSS({
  // Set yourRegion to the region where your bucket is located. For example, if your bucket is in the China (Hangzhou) region, set yourRegion to oss-cn-hangzhou.
  region: 'yourRegion',
  // Obtain access credentials from environment variables. Before you run this sample code, make sure that the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are configured.
  accessKeyId: process.env.OSS_ACCESS_KEY_ID,
  accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET,
  authorizationV4: true,
  // Specify the bucket name, for example, examplebucket.
  bucket: 'examplebucket',
});

const headers = {    
  // Specify the access control list (ACL) of the object.
  'x-oss-object-acl': 'private',
  // Specify the storage class of the object.
  'x-oss-storage-class': 'Standard',  
  // Specify the server-side encryption method. In this example, server-side encryption with OSS-managed keys (SSE-OSS) is used.
  'x-oss-server-side-encryption': 'AES256',  
};

async function append () {
  // Perform the first append upload. The return value indicates the position for the next append operation.
  // objectName specifies the full path of the object, not including the bucket name. For example, destfolder/examplefile.txt.
  // localFile specifies the full path of the local file, including the file extension. For example, /users/local/examplefile.txt.
  let result = await client.append('objectName', 'localFile'
  // Custom headers and metadata.
  //,{headers} 
  )

  // Perform the second append operation. The position for the next append is the value of nextAppendPosition returned from the previous append operation.
  result = await client.append('objectName', 'localFile', {
    position: result.nextAppendPosition
  })
}

append();

References

For more information about the AppendObject API operation, see AppendObject.