Skip to content

Commit

Permalink
Merge pull request #103 from CulturalMe/devel
Browse files Browse the repository at this point in the history
Version 0.7.1
  • Loading branch information
gsuess committed May 20, 2015
2 parents 7946982 + cbc1dbb commit 5b98497
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 10 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Slingshot Changelog
===================

## Version 0.7.1

### Enhancements

* Added support for dynamic content-disposition for S3 and Google Cloud ([#64](https://github.com/CulturalMe/meteor-slingshot/issues/64))

## Version 0.7.0

### Enhancements
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ Slingshot.fileRestrictions("myFileUploads", {
maxSize: 10 * 1024 * 1024 // 10 MB (use null for unlimited)
});
```

Important: The `fileRestrictions` must be declared before the the directive is instantiated.

### Server side

On the server we declare a directive that controls upload access rules:
Expand Down Expand Up @@ -551,8 +554,10 @@ the second is the meta-information that can be passed by the client.

`cacheControl` String (optional) - RFC 2616 Cache-Control directive

`contentDisposition` String (optional) - RFC 2616 Content-Disposition directive.
Default is the uploaded file's name (inline). Use null to disable.
`contentDisposition` String or Function (optional) - RFC 2616
Content-Disposition directive. Default is the uploaded file's name (inline). If
it is a function then it takes the same context and arguments as the `key`
function. Use null to disable.

#### Rackspace Cloud (`Slingshot.RackspaceFiles`)

Expand Down
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package.describe({
name: "edgee:slingshot",
summary: "Directly post files to cloud storage services, such as AWS-S3.",
version: "0.7.0",
version: "0.7.1",
git: "https://github.com/CulturalMe/meteor-slingshot"
});

Expand Down
26 changes: 19 additions & 7 deletions services/aws-s3.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Slingshot.S3Storage = {
}),

cacheControl: Match.Optional(String),
contentDisposition: Match.Optional(Match.OneOf(String, null))
contentDisposition: Match.Optional(Match.OneOf(String, Function, null))
},

directiveDefault: _.chain(Meteor.settings)
Expand All @@ -61,6 +61,22 @@ Slingshot.S3Storage = {
})
.value(),

getContentDisposition: function (method, directive, file, meta) {
var getContentDisposition = directive.contentDisposition;

if (!_.isFunction(getContentDisposition)) {
getContentDisposition = function () {
var filename = file.name && encodeURIComponent(file.name);

return directive.contentDisposition || filename &&
"inline; filename=\"" + filename + "\"; filename*=utf-8''" +
filename;
};
}

return getContentDisposition.call(method, file, meta);
},

/**
*
* @param {{userId: String}} method
Expand All @@ -86,9 +102,8 @@ Slingshot.S3Storage = {
"acl": directive.acl,

"Cache-Control": directive.cacheControl,
"Content-Disposition": directive.contentDisposition || file.name &&
"inline; filename=" + quoteString(file.name, '"') +
"; filename*=utf-8''" + encodeURIComponent(file.name)
"Content-Disposition": this.getContentDisposition(method, directive,
file, meta)
},

bucketUrl = _.isFunction(directive.bucketUrl) ?
Expand Down Expand Up @@ -200,9 +215,6 @@ Slingshot.S3Storage.TempCredentials = _.defaults({
}
}, Slingshot.S3Storage);

function quoteString(string, quotes) {
return quotes + string.replace(quotes, '\\' + quotes) + quotes;
}

function formatNumber(num, digits) {
var string = String(num);
Expand Down

0 comments on commit 5b98497

Please sign in to comment.