Skip to content

Commit

Permalink
Merge pull request #85 from CulturalMe/fix-download-path-84
Browse files Browse the repository at this point in the history
Fix download url
  • Loading branch information
gsuess committed Mar 29, 2015
2 parents d9af24f + 1f68368 commit 511738b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ Slingshot Changelog

* Added a way to get the server response to the uploader. ([#82](https://github.com/CulturalMe/meteor-slingshot/issues/82))

### Bug Fixes

* Fixed bad S3 download url generation where the download url would start with `https:/` instead of `https://`. ([#84](https://github.com/CulturalMe/meteor-slingshot/issues/84))

## Version 0.6.0

### Bug Fixes
Expand Down
39 changes: 21 additions & 18 deletions services/aws-s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ Slingshot.S3Storage = {
check(acl, String);

return [
"private",
"public-read",
"public-read-write",
"authenticated-read",
"bucket-owner-read",
"bucket-owner-full-control",
"log-delivery-write"
].indexOf(acl) >= 0;
"private",
"public-read",
"public-read-write",
"authenticated-read",
"bucket-owner-read",
"bucket-owner-full-control",
"log-delivery-write"
].indexOf(acl) >= 0;
})),

key: Match.OneOf(String, Function),
Expand Down Expand Up @@ -74,8 +74,6 @@ Slingshot.S3Storage = {
upload: function (method, directive, file, meta) {
var url = Npm.require("url"),

path = Npm.require("path"),

policy = new Slingshot.StoragePolicy()
.expireIn(directive.expire)
.contentLength(0, Math.min(file.size, directive.maxSize || Infinity)),
Expand All @@ -98,24 +96,29 @@ Slingshot.S3Storage = {
directive.bucketUrl(directive.bucket, directive.region) :
directive.bucketUrl,

downloadPath = path.join((directive.cdn || bucketUrl), payload.key),

download = url.parse(downloadPath);
downloadUrl = [
(directive.cdn || bucketUrl),
payload.key
].map(function (part) {
return part.replace(/\/+$/, '');
}).join("/");

this.applySignature(payload, policy, directive);

console.log(downloadUrl);

return {
upload: bucketUrl,
download: url.format(download),
download: downloadUrl,
postData: [{
name: "key",
value: payload.key
}].concat(_.chain(payload).omit("key").map(function (value, name) {
return !_.isUndefined(value) && {
name: name,
value: value
};
}).compact().value())
name: name,
value: value
};
}).compact().value())
};
},

Expand Down

0 comments on commit 511738b

Please sign in to comment.