Object metadata contains HTTP headers and user metadata. For more information, see Manage object metadata in OSS User Guide.

When you upload an object to OSS, you can specify the information of certain properties. The information is called object metadata. Object metadata is stored together with the object during uploads, and returned with the object when the object is downloaded.

Object metadata is transferred as HTTP headers in requests and responses. According to the HTTP protocol, HTTP headers cannot contain complex characters. Therefore, object metadata can contain only visible ASCII characters. Metadata cannot contain line feeds.

Note The total size of object metadata cannot exceed 8 KB.

When you call put, putStream, or multipartUpload, you can specify the meta parameter to specify the object metadata.

let OSS = require('ali-oss')

let client = new OSS({
  region: '<Your region>',
  accessKeyId: '<Your AccessKeyId>',
  accessKeySecret: '<Your AccessKeySecret>',
  bucket: '<Your bucket name>',
});

async function put () {
  try {
    let result = await client.put('object-name', 'local-file', {
    meta: {
      year: 2016,
      people: 'mary'
    }
  });
  console.log(result);
  } catch (e) {
    console.log(e);
  }
}

put();
        

You can also call putMeta to modify the object metadata.

let OSS = require('ali-oss')

let client = new OSS({
  region: '<Your region>',
  accessKeyId: '<Your AccessKeyId>',
  accessKeySecret: '<Your AccessKeySecret>',
  bucket: '<Your bucket name>',
});

async function putMeta () {
  try {
    let result = await client.putMeta('object-name', {
    meta: {
      year: 2015,
      people: 'mary'
    }
  });
  console.log(result);
  } catch (e) {
    console.log(e);
  }
}

putMeta();