Created
September 20, 2016 20:47
-
-
Save flimshaw/fa2c83358878d134405a2bde4789cbf4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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