I have a node.js project that uses express. Within this project I have a models
folder that contains different models used in the project.
In my MosaicParTileStreamerS3Only
model I have the following:
'use strict';
var GlobalMercator = require('./GlobalMercator.js');
var S3 = require('./S3.js');
var binary = require('binary');
var bufferpack = require('bufferpack');
function MosaicParTileStreamerS3Only() {
};
Further into this model, I use S3
without any issues:
MosaicParTileStreamerS3Only.prototype.Init = function(filepath, index, s3config){
var retval = false;
this.s3 = new S3(s3config.access_key, s3config.secret_key, s3config.host);
var host = s3config.host;
var bucket = s3config.bucket;
filepath = s3config.tile_directory + filepath;
var request = this.s3.getObject(bucket, filepath, false, 0,
this.HEADER_SIZE + 5 * this.RESOLUTION_ENTRY_SIZE + this.TILE_COUNT_SIZE
+ 256 * this.TILE_ENTRY_SIZE);
...
Placing a breakpoint on the second line (this.s3 = new S3(s3config.access_key, s3config.secret_key, s3config.host);
) shows that S3
is being brought in as a function.
I have the following in my S3Request.js
:
'use strict';
var S3 = require('./S3.js');
var STDClass = require('stdclass');
var Curl = require('node-libcurl').Curl;
var parseString = require('xml2js').parseString;
function S3Request(verb, bucket, uri, endpoint){
this.headers = '';
this.endpoint = endpoint;
this.verb = verb;
this.bucket = bucket;
this.uri = (uri !== '' ? '/' + '%2F'.replace('/', encodeURIComponent(uri)) : '/');
...
}
Later on in this model I try using S3
:
var test = new S3();
headers['Authorization'] = S3.getSignature(this.verb + '\n' +
this.headers['Content-MD5'] + "\n" + this.headers['Content-Type']
+ "\n" + this.headers["Date"] + amz + "\n" + this.resource);
I get the following error:
TypeError: S3 is not a function
Putting a breakpoint on var test = new S3();
shows that in this file S3
is considered an object:
Any clue as to what's going wrong?