Skip to content

Commit

Permalink
Support non-amazon endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
radare committed Jan 22, 2016
1 parent d0946f6 commit d9b3630
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* Uses heuristics to compute multipart ETags client-side to avoid uploading
or downloading files unnecessarily.
* Automatically provide Content-Type for uploads based on file extension.
* Support third-party S3-compatible platform services like Ceph

See also the companion CLI tool which is meant to be a drop-in replacement for
s3cmd: [s3-cli](https://github.com/andrewrk/node-s3-cli).
Expand All @@ -33,7 +34,9 @@ var client = s3.createClient({
s3Options: {
accessKeyId: "your s3 key",
secretAccessKey: "your s3 secret",
region: "your region"
region: "your region",
// endpoint: 's3.yourdomain.com',
// sslEnabled: false
// any other options are passed to new AWS.S3()
// See: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#constructor-property
},
Expand Down
14 changes: 10 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ Client.prototype.uploadFile = function(params) {
uploader.progressAmount = 0;
uploader.progressTotal = 0;
uploader.abort = handleAbort;
uploader.getPublicUrl = function() {
return getPublicUrl(s3Params.Bucket, s3Params.Key, self.s3.config.region, self.s3.config.endpoint);
}
uploader.getPublicUrlHttp = function() {
return getPublicUrlHttp(s3Params.Bucket, s3Params.Key, self.s3.config.endpoint);
}

var localFile = params.localFile;
var localFileStat = null;
Expand Down Expand Up @@ -1419,21 +1425,21 @@ function encodeSpecialCharacters(filename) {
});
}

function getPublicUrl(bucket, key, bucketLocation) {
function getPublicUrl(bucket, key, bucketLocation, endpoint) {
var nonStandardBucketLocation = (bucketLocation && bucketLocation !== 'us-east-1');
var hostnamePrefix = nonStandardBucketLocation ? ("s3-" + bucketLocation) : "s3";
var parts = {
protocol: "https:",
hostname: hostnamePrefix + ".amazonaws.com",
hostname: hostnamePrefix + '.' + (endpoint || "amazonaws.com"),
pathname: "/" + bucket + "/" + encodeSpecialCharacters(key),
};
return url.format(parts);
}

function getPublicUrlHttp(bucket, key) {
function getPublicUrlHttp(bucket, key, endpoint) {
var parts = {
protocol: "http:",
hostname: bucket + ".s3.amazonaws.com",
hostname: bucket + '.' + (endpoint || "s3.amazonaws.com"),
pathname: "/" + encodeSpecialCharacters(key),
};
return url.format(parts);
Expand Down

0 comments on commit d9b3630

Please sign in to comment.