mirror of https://github.com/therootcompany/s3.js
AJ ONeal
4 years ago
2 changed files with 88 additions and 23 deletions
@ -0,0 +1,51 @@ |
|||
'use strict'; |
|||
|
|||
require('dotenv').config(); |
|||
var env = process.env; |
|||
var s3 = require('../index.js'); |
|||
|
|||
var accessKeyId = env.AWS_ACCESS_KEY; |
|||
var secretAccessKey = env.AWS_SECRET_ACCESS_KEY; |
|||
var region = env.AWS_REGION; |
|||
var bucket = env.AWS_BUCKET; |
|||
var prefix = env.AWS_BUCKET_PREFIX; |
|||
|
|||
var key = process.argv[2]; |
|||
var filepath = process.argv[3]; |
|||
var fs = require('fs'); |
|||
|
|||
if (!key || !filepath) { |
|||
console.info('Usage: s3-download.js s3-key-name ./path/to/file.bin'); |
|||
process.exit(1); |
|||
} |
|||
|
|||
async function run() { |
|||
// GET STREAMED FILE
|
|||
await s3 |
|||
.get({ |
|||
accessKeyId, |
|||
secretAccessKey, |
|||
region, |
|||
bucket, |
|||
prefix, |
|||
key |
|||
}) |
|||
.then(function(resp) { |
|||
console.log(resp.url); |
|||
return fs.promises.writeFile(filepath, resp.body); |
|||
}) |
|||
.catch(function(err) { |
|||
console.error('Error:'); |
|||
console.error('GET Response:'); |
|||
if (err.response) { |
|||
console.error(err.response.statusCode); |
|||
console.error(err.response.headers); |
|||
console.error(err.url); |
|||
} else { |
|||
console.error(err); |
|||
} |
|||
process.exit(1); |
|||
}); |
|||
} |
|||
|
|||
run(); |
Loading…
Reference in new issue