This topic describes how to list all objects in a bucket.

Use list to list all objects in the current bucket. Parameters are described as follows:

  • prefix: only lists objects with the specified prefix.
  • marker: only lists objects whose names come after the marker value.
  • delimiter: separates object names. CommonPrefixes specify a set of substrings that start with a specified prefix and end with the first specified delimiter.
  • max-keys: the maximum number of objects to be returned.

Use the following code to list all objects in a bucket:

let OSS = require('ali-oss');
let client = new OSS({
  region: '<Your region>',
  accessKeyId: '<Your AccessKeyId>',
  accessKeySecret: '<Your AccessKeySecret>',
  bucket: 'Your bucket name'
});
async function list () {
  {
    // If no parameter is specified, a maximum of 1,000 objects can be returned by default.
    let result = await client.list();
    console.log(result);
    // Continue to list objects based on the nextMarker field value.
    if (result.isTruncated) {
      let result = await client.list({
        marker: result.nextMarker
      });
    }
  // List all objects that are prefixed with "my-."
  let result = await client.list({
     prefix: 'my-'
  });
  console.log(result);
  // List all objects whose names are prefixed with "my-" and come after the "my-object" marker.
  let result = await client.list({
     prefix: 'my-',
     marker: 'my-object'
  });
  console.log(result);
  } catch (e) {
    console.log(e);
  }
}
list();