2014-12-02 90 views

回答

0

假設您有一個函數listFiles,它返回要下載的存儲區中的密鑰數組,以及接受文件密鑰(名稱)並下載並刪除它的函數downloadFile

你想對listFiles返回的所有文件同時調用downloadFile對不對?使用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; 
     } 
    }); 
}); 
+0

我已經下載了一個文件。我正在尋找一種方法來下載一個拍攝桶..類似[downloadBucket()或transferBucket()..等] – 2014-12-07 13:08:41

+1

該功能不存在於S3 – Max 2014-12-07 13:59:38

0

可以使用下面的命令中使用aws cli

aws s3 sync s3://yourbucket . 

如果你必須使用node那麼你可以使用execspwan

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