All Products
Search
Document Center

Object Storage Service:Upload content from local memory (Node.js SDK)

Last Updated:Nov 29, 2025

This document describes how to upload content from local memory to OSS.

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 policies.

API

Action

Definition

PutObject

oss:PutObject

Uploads an object.

oss:PutObjectTagging

When uploading an object, if you specify object tags through x-oss-tagging, this permission is required.

kms:GenerateDataKey

When uploading an object, if the object metadata contains X-Oss-Server-Side-Encryption: KMS, these two permissions are required.

kms:Decrypt

Sample code

The following code shows how to upload content from local memory to OSS.

const OSS = require('ali-oss');

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

async function putBuffer () {
  try {
    const result = await client.put('object-name', new Buffer.from('hello world'));
    console.log(result);
  } catch (e) {
    console.log(e);
  }
}

putBuffer();

References

For more information about the API operation for simple uploads, see PutObject.