I am working on a Node.js project that relies on the response of getObject from AWS. Currently, I can access the data I need and store it in a variable (header), but do not know how to make it available in the main function.
TileStreamerS3.prototype.Init = function(filepath, index, s3config){
var retval = false;
AWS.config.update({accessKeyId: s3config.access_key, secretAccessKey: s3config.secret_key});
var blc = new BlockLibraryConfigs();
var awsConfig = blc.awsConfig;
AWS.config.update({region: awsConfig.region});
var aws = new AWS.S3();
var params = {
Bucket: s3config.bucket,
Key: s3config.tile_directory + filepath,
Range: 'bytes=0-27'
};
aws.getObject(params, function(err, data){
if(err == null){
var header = bufferpack.unpack('<7I', data.Body);
return header;
}
});
};
How do I return the header variable? I saw a possible solution that used JQuery, but I'm on Windows and am having issues getting JQuery to work with Node. I don't want to have to go down that path if there's a better way to do it.
UPDATE: I know there are multiple questions regarding returning values from asynchronous functions. I think what's tripping me up is that aws.getObject() is a function that is taking in another function as a parameter. I want to return the header value from the function that is a parameter for the aws.getObject() function. Furthermore, I have no access to change the getObject() function.
deferred: api.jquery.com/jquery.deferred