Last active
August 13, 2017 14:51
-
-
Save apeque/55861cdb72e377d37fdc to your computer and use it in GitHub Desktop.
Image Conversion / S3 Upload Test
This file contains hidden or 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 config = require("../config.js"); | |
var gm = require("gm"), imageMagick = gm.subClass({ imageMagick: true }); | |
var httpg = require("http-get"); | |
var imgSize = require("image-size"); | |
var Q = require('Q'); | |
var s3 = require('knox'); | |
var _ = require("underscore"); | |
var image = 'tmp/test.jpeg'; | |
var client = s3.createClient({ | |
key: config.aws.key, | |
secret: config.aws.secret, | |
bucket: config.paths.users.bucket | |
}); | |
var upload = function(file, name){ | |
var d = Q.defer(); | |
client.putFile(file, name, { 'x-amz-acl': 'public-read' }, function(err,upload){ | |
if(err){ | |
d.reject(); | |
} else { | |
d.resolve(config.paths.users.path + name); | |
} | |
}); | |
return d.promise; | |
}; | |
var start = new Date().getTime(); | |
var images = ['https://lh5.ggpht.com/tp5jKKnLQmbOznGh7q1FhS66YjGw2PlLuZda95XjxcZg32BAumCdcDsjX83krUHsO6Am=h900-rw', 'https://lh5.ggpht.com/tp5jKKnLQmbOznGh7q1FhS66YjGw2PlLuZda95XjxcZg32BAumCdcDsjX83krUHsO6Am=h900-rw', 'https://lh5.ggpht.com/tp5jKKnLQmbOznGh7q1FhS66YjGw2PlLuZda95XjxcZg32BAumCdcDsjX83krUHsO6Am=h900-rw', 'https://lh5.ggpht.com/tp5jKKnLQmbOznGh7q1FhS66YjGw2PlLuZda95XjxcZg32BAumCdcDsjX83krUHsO6Am=h900-rw', 'https://lh5.ggpht.com/tp5jKKnLQmbOznGh7q1FhS66YjGw2PlLuZda95XjxcZg32BAumCdcDsjX83krUHsO6Am=h900-rw', 'https://lh5.ggpht.com/tp5jKKnLQmbOznGh7q1FhS66YjGw2PlLuZda95XjxcZg32BAumCdcDsjX83krUHsO6Am=h900-rw', 'https://lh5.ggpht.com/tp5jKKnLQmbOznGh7q1FhS66YjGw2PlLuZda95XjxcZg32BAumCdcDsjX83krUHsO6Am=h900-rw']; | |
_.each(images, function(o) { | |
var options = { url: o }; | |
httpg.get(options, image, function(err,res){ | |
console.log('get'); | |
//console.log(new Date().getTime() - start); | |
//imgSize(res.file, function(err,val){ | |
//imageMagick(res.file).resize(1200).write(res.file, function(err){ | |
upload(res.file, 'xxx').then(function(url){ | |
//console.log('upload'); | |
//console.log(url); | |
console.log(new Date().getTime() - start); | |
//fs.unlink(res.file); | |
//d.resolve(url); | |
}); | |
//}); | |
//}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment