Last active
January 3, 2016 11:49
-
-
Save gabrielstuff/8458313 to your computer and use it in GitHub Desktop.
Meteor AWS using aws smart package, npm smart package and native request from npm module request.
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
Meteor.call('getFile', 'ksxxxx.domain.com', 80, '/path/last.gif', function(res, err){ | |
console.log('YEAH: '+res); | |
}); |
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
AWS.config.update({ | |
accessKeyId: 'xxx', | |
secretAccessKey: 'xxx' | |
}); | |
s3 = new AWS.S3(); | |
var MeteorAWS = function() { | |
this.name = ''; | |
this.extension = ''; | |
this.baseUrl = 'https://s3-eu-west-1.amazonaws.com/bucket/'; | |
this.url = ''; | |
var _self = this; | |
this.uploadAWS = function(blob, name, type) { | |
var response = s3.putObjectSync({ | |
Bucket: "bucketbucket", | |
ACL: 'public-read', | |
Key: name, | |
ContentType: type, | |
Body: new Buffer(blob, 'binary') | |
}); | |
console.log(response); | |
totalUrl = _self.baseUrl + _self.name + '.' + _self.extension; | |
return Meteor.call('sunrise', { | |
url: totalUrl | |
}); | |
}; | |
this.getFile = function(host, port, path) { | |
var request = Meteor.require('request'); | |
host = host || 'www.google.com'; | |
port = port || 80; | |
path = path || '/images/logos/ps_logo2.png'; | |
_self.extension = path.split('/').pop().split('.').pop(); | |
_self.url = 'http://' + host + ':' + port + path; | |
var wrapRequest = Meteor._wrapAsync(request.get); | |
var boundRequest = Meteor.bindEnvironment(function(response) { | |
var imagedata = response.body; | |
_self.name = path.split('/').pop().split('.').shift() + new Date().getTime(); | |
console.log('uploading...'); | |
res = _self.uploadAWS(imagedata, _self.name + '.' + _self.extension, 'image/' + _self.extension); | |
return res; | |
}, function(e) { | |
throw e; | |
}); | |
console.log('downloading...'); | |
request.get({ | |
url: _self.url, | |
encoding: 'binary' | |
}, function(err, response) { | |
boundRequest(response); | |
}); | |
}; | |
}; | |
var meteorAWS = new MeteorAWS(); | |
Meteor.methods({ | |
uploadAWS: meteorAWS.uploadAWS, | |
getFile: meteorAWS.getFile | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the argument list is reversed:
function (err, res) { console.log('YEAH: '+res); }