Skip to content

Instantly share code, notes, and snippets.

@flimshaw
Created September 20, 2016 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flimshaw/fa2c83358878d134405a2bde4789cbf4 to your computer and use it in GitHub Desktop.
Save flimshaw/fa2c83358878d134405a2bde4789cbf4 to your computer and use it in GitHub Desktop.
var AWS = require('aws-sdk'),
fs = require('fs'),
awsCredentialsPath = './aws.credentials.json',
sqsQueueUrl = 'SQS_QUEUE_URL',
http = require('http'),
sqs;
// Load credentials from local json file
AWS.config.loadFromPath(awsCredentialsPath);
function retrieveFile(filename, callback) {
var s3Stream = require('s3-upload-stream')(new AWS.S3());
var upload = s3Stream.upload({
"Bucket": "BUCKET_NAME",
"Key": filename
});
upload.on('error', function (error) {
console.log(error);
});
upload.on('part', function (details) {
callback();
});
// get the given filename from the path given
http.get({
hostname: 'cdn.gea.esac.esa.int',
port: 80,
path: `/Gaia/gaia_source/csv/${filename}`,
agent: false // create a new agent just for this one request
}, (res) => {
// stream-upload the file to Amazon S3 as it comes in
res.pipe(upload);
});
}
module.exports = retrieveFile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment