简体   繁体   English

如何对 Aws s3 列表 object 进行分页?

[英]How to paginate Aws s3 list object?

I have over 20000 images in s3 and I want to paginate the first 100 after clicking on pagination 2nd link it should load the second 100 images and so on.我在 s3 中有超过 20000 张图像,我想在单击分页第二个链接后对前 100 张进行分页,它应该加载第二个 100 张图像,依此类推。

const params = { Bucket: "test-bucket", Delimiter: '/', MaxKeys: 100, Prefix: "thumbnail_images/Q" };

async function* listAllKeys(params) {
  try {
    do {
      const data = await s3.listObjectsV2(params).promise();
      params.ContinuationToken = data.NextContinuationToken;
      yield data;
    } while (params.ContinuationToken);
  } catch (err) {
    return err;
  }
};

I am using aws-sdk node package.我正在使用aws-sdk节点 package。

s3 doesn't provide any pagination feature but you can develop your own. s3 不提供任何分页功能,但您可以开发自己的分页功能。

use s3 get object list to get a list of all images and store it in var imageList.使用 s3 get object list 获取所有图像的列表并将其存储在 var imageList 中。 on first request from UI pass(page:0) the images from imageList[100 0:(100 0)+100] on second request from UI pass(page:1) the images from imageList[100 1:(100 1)+100] and so on.在来自 UI 的第一次请求时,传递(页面:0)来自 imageList[100 0:(100 0)+100] 的图像 在来自 UI 的第二次请求时,传递(页面:1)来自 imageList[100 1:(100 1)+ 的图像100] 等等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM