title: AWS Pagination listObjects node.js
body: <p>Hi I am currently wanting to list images within a store with the use of pagination. I need to display a specified number of images each time and allow the loop to stop on the page number i have specified. (example. 30 images per page and I need page 3 I will need to list the 3rd page of images). So far it iterates through all the files, I just need to list objectsPerPage depending on the pageCount</p>
  
  <p><strong>(GET /list/{storeid}?page={pageNumber}&amp;per_page={perPage}</strong></p>
  
  <pre><code>var shopId = event.shopkeeper + "/";
  var objectsPerPage = event.perPage;
  var pageCount = event.pageNumber;
  
  var params = {
      Bucket: AWS_Bucket,
      Delimiter: '/',
      Prefix: shopId,
      MaxKeys: objectsPerPage
  }; var dataContents = [];
  
  function s3ListObjects() {
  s3.listObjects(params, function(err, data) {
      if (err) {
          console.log("listS3Objects Error:", err);
      } else {
          var contents = data.Contents;
          dataContents = dataContents.concat(contents);
          if (data.IsTruncated) {
              params.Marker = contents[contents.length-1].Key;
              s3ListObjects(params, callback);
          } else {
              console.log(dataContents);
          }
      }
  });
  }
  </code></pre>