简体   繁体   English

获取node.js应用程序以从AWS S3存储桶中提取多个页面时遇到问题(超过1000个文件)

[英]Having issues getting node.js app to pull multiple pages from AWS S3 Bucket (over 1000 files)

I have inherited a node.js app and I'm trying to fake my way through fixing our issue. 我继承了一个node.js应用程序,并且试图通过修复问题来伪装自己的方式。 Everything was working great until we reached the 1000 file page limit for an AWS bucket. 在达到AWS存储桶的1000个文件页面限制之前,一切工作都很好。 I have made attempts at using the .eachPage() standard and async processes and also using the .hasNextPage() process and have been unable to get it to work. 我已经尝试过使用.eachPage()标准和异步进程以及.hasNextPage()进程,但无法使其正常工作。 I feel like of my attempts, this version is the closest to working. 我觉得我的尝试最接近这个版本。 In my mind, it seems to make sense, but it pulls only the first 1000 files. 在我看来,这似乎很有意义,但它只会提取前1000个文件。 Can someone help point me in the right direction to get those extra pages of data to load? 有人可以帮我指出正确的方向,以便加载这些额外的数据页吗?

// Get file list from AWS s3
        s3.listObjects({
            Bucket: config.aws.s3.bucket
        }).eachPage(function(error, data, done) {
            console.log('S3 Data', data);
            done();
            if (error) {
                var err = new Error('Couldn\'t retrieve file list.');
                err.status = 404;
                return next(err);
            } else {
                return res.render('user/home', {
                    userName: user.firstName + ' ' + user.lastName,
                    dummy: (new Date()).getTime(),
                    products: util.parseProductMetaData(config.subscriptions),
                    weeks: util.parseS3FileList(user.subscriptions,
                        data.Contents,
                        config.aws.s3.worksheetFolder,
                        config.subscriptions,
                        config.aws.s3.fileRegex),
                    userHeaderContext: {
                        loggedIn: true
                    },
                    city: user.city,
                    state: user.state,
                    userFormContext: {
                        disabled: true,
                        _id: user._id,
                        email: user.email,
                        firstName: user.firstName,
                        lastName: user.lastName,
                            return val;
                        })
                    }
                });
            }
        });

Seems like you have some conflicting JS concepts here. 似乎您在这里有一些冲突的JS概念。 When you use the asynchronous style with three parameters, as soon as you call done() the next page will execute -- since you do this right away, the next page will immediately start executing so it doesn't really make sense to return something later on. 当您将异步样式与三个参数一起使用时,一旦调用done() ,下一页将立​​即执行-由于您立即执行此操作,因此下一页将立​​即开始执行,因此return某些内容实际上没有任何意义稍后的。

You're also calling res.render() for each page of files, which is probably not what you intended and why it looks like only 1000 files are listed (actually you render the first 1000, then continue doing lots of work in the background after sending the result!). 您还在文件的每一页上调用res.render() ,这可能不是您想要的,并且为什么看起来只列出了1000个文件(实际上您渲染了前1000个文件,然后继续在后台执行大量工作发送结果后!)。 I would recommend something like the following: 我建议类似以下内容:

var files = [];
s3.listObjects({
  Bucket: config.aws.s3.bucket
}).eachPage(function(error, data){
  if(err) return;
  files.push(data.Contents);
});

// Now do something with all the files
res.render('whatever',files);

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

相关问题 在 Node.js 应用程序中从 AWS S3 下载文件 - Download files from AWS S3 in Node.js app AWS S3 Node.js SDK:需要一次从一个存储桶下载所有文件 - AWS S3 Node.js SDK: Need to Download all files from one bucket at once 尝试使用node.js和exec + aws cli将所有文件从一个S3存储桶移动到另一个存储桶 - Trying to move all files from one S3 bucket to another using node.js and exec + aws cli 从node.js中的aws-sdk将JSON文件上传到aws s3存储桶 - Upload JSON file to aws s3 bucket from aws-sdk in node.js 对象存在于Node.JS的AWS S3存储桶中 - object exists in AWS S3 bucket in Node.JS AWS Node.js无法创建S3存储桶? - AWS node.js not creating S3 bucket? 使用节点 js 将图像上传到 AWS s3 存储桶时遇到问题 - Having trouble uploading image to AWS s3 bucket with node js 尝试从我的 S3 存储桶访问文件时,在我的 Node.js 应用程序中获取“禁止:空” - Getting "Forbidden: null" in my Node.js application when trying to access files from my S3 bucket 当节点文件超过1000个时,使用Node中的s3将存储桶的所有内容推入数组 - using s3 in Node to push all contents of a Bucket into an array when over 1000 files 有没有一种简单的方法可以使用 node.js 从 s3 存储桶中的最新文件夹中获取最新文件名 - Is there an easy way of getting the latest filename from the latest folder in s3 bucket using node.js
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM