This document describes how to upload content from local memory to Object Storage Service (OSS).

Sample code

This following code provides an example on how to upload content from local memory to OSS.

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

const client = new OSS({
  // Specify the region in which the bucket is located. For example, if the bucket is located in the China (Hangzhou) region, set the region to oss-cn-hangzhou. 
  region: 'yourregion',
  // The AccessKey pair of an Alibaba Cloud account has permissions on all API operations. Using these credentials to perform operations in OSS is a high-risk operation. We recommend that you use a RAM user to call API operations or perform routine O&M. To create a RAM user, log on to the RAM console. 
  accessKeyId: 'yourAccessKeyId',
  accessKeySecret: 'yourAccessKeySecret'
  // Set yourbucketname to the name of your bucket. 
  bucket: 'yourbucketname', 
});

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

putBuffer();

References

For more information about the API operation that you can call to perform simple upload, see PutObject.