简体   繁体   English

AWS S3 Node.js SDK:需要一次从一个存储桶下载所有文件

[英]AWS S3 Node.js SDK: Need to Download all files from one bucket at once

Currently I can iterate over all files in bucket and download one by one, using node.js sdk.目前我可以遍历bucket中的所有文件并使用node.js sdk一一下载。 I need to download all files from S3 bucket at once.我需要一次从 S3 存储桶下载所有文件。 then remove it from bucket.然后将其从桶中取出。

This higher-level Node S3 library has a downloadDir function which syncs a remote S3 bucket with a local directory.这个更高级别的节点 S3 库有一个downloadDir函数,该函数将远程 S3 存储桶与本地目录同步。

https://github.com/andrewrk/node-s3-client#clientdownloaddirparams https://github.com/andrewrk/node-s3-client#clientdownloaddirparams

You can use the aws cli using the command below:您可以使用以下命令使用aws cli

aws s3 sync s3://yourbucket .

If you have to use node then you can use exec or spwan .如果必须使用node则可以使用execspwan

const exec = require('child_process').exec;
exec('aws s3 sync s3://yourbucket .', (err, stdout, stderr) => {});

Let's say you have a function listFiles that returns an array of the Keys in the bucket you want to download and a function downloadFile that accepts a file Key (name) and downloads it and then deletes it.假设您有一个函数listFiles返回要下载的存储桶中的键数组,还有一个函数downloadFile接受文件键(名称)并下载它,然后将其删除。

You want to call downloadFile simultaneously on all files returned from listFiles right?您想对从listFiles返回的所有文件同时调用downloadFile对吗? Use the async library.使用async库。

function listFiles(cb) {
    s3.stuff(params, cb);
}
function downlaodFile(key, cb) {
    s3.stuff(key, cb);
}
listFiles(function (err, fileKeys) {
    if (err) {
        throw err;//don't really but this is just an example
    }
    async.each(fileKeys, downloadFile, function done(err) {
        if (err) {
            throw err;
        }
    });
});

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

相关问题 尝试使用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 S3 下载文件 - Download files from AWS S3 in Node.js app 从node.js中的aws-sdk将JSON文件上传到aws s3存储桶 - Upload JSON file to aws s3 bucket from aws-sdk in node.js 想从 Node.js 中的 S3 Bucket 下载文件 - Want to download file from S3 Bucket in Node.js 如何使用 Node.js 的 AWS SDK 将 Amazon S3 中的所有对象从一个前缀复制/移动到另一个前缀 - How to copy/move all objects in Amazon S3 from one prefix to other using the AWS SDK for Node.js 如何使用IAM访问AWS S3上的存储桶 - 使用Node.js(aws-sdk)? - How to access bucket on AWS S3 using IAM - with Node.js (aws-sdk)? 如何使用Node中的aws-sdk模块从S3下载具有匹配密钥的所有文件? - how to download all files with matching key from S3, using aws-sdk module in Node? 有没有办法使用AWS SDK for Node.js检查S3存储桶中是否存在路径? - Is there any way to check existence of a path in S3 bucket using AWS SDK for Node.js? 获取node.js应用程序以从AWS S3存储桶中提取多个页面时遇到问题(超过1000个文件) - Having issues getting node.js app to pull multiple pages from AWS S3 Bucket (over 1000 files) 对象存在于Node.JS的AWS S3存储桶中 - object exists in AWS S3 bucket in Node.JS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM