Created
July 17, 2014 20:16
-
-
Save deleteman/2f53841314bec8ef6480 to your computer and use it in GitHub Desktop.
Download and upload into S3
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
function getScreenshots(urls) { | |
console.log("Getting screenshots for: " + urls.length + " files") | |
var client = knox.createClient({ | |
key: config.s3.key, | |
secret: config.s3.secret, | |
bucket: config.s3.bucket | |
}); | |
return function(callback) { | |
async.mapSeries(urls, function(url, cb) { | |
console.log("Getting: " + url) | |
request.get(url, function(err, res, body) { | |
if(!err) { | |
var fileName = getFileName(url) | |
var contentType = mime.lookup(fileName) | |
console.log("Size: " + body.length) | |
console.log("Headers:") | |
console.log(res.headers) | |
client.putBuffer(body, fileName, {'Content-Type': contentType, 'x-amz-acl': 'public-read'}, function(err, res) { | |
if(err) console.log(err) | |
console.log("file uploaded..." + fileName) | |
cb(err, fileName) | |
}) | |
} else { | |
console.log("Error on request: " + err) | |
cb() | |
} | |
}) | |
}, callback) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment