[英]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.