Skip to content

Commit 5b98497

Browse files
committed
Merge pull request #103 from CulturalMe/devel
Version 0.7.1
2 parents 7946982 + cbc1dbb commit 5b98497

File tree

5 files changed

+55
-10
lines changed

5 files changed

+55
-10
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
Slingshot Changelog
22
===================
33

4+
## Version 0.7.1
5+
6+
### Enhancements
7+
8+
* Added support for dynamic content-disposition for S3 and Google Cloud ([#64](https://github.com/CulturalMe/meteor-slingshot/issues/64))
9+
410
## Version 0.7.0
511

612
### Enhancements

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ Slingshot.fileRestrictions("myFileUploads", {
6060
maxSize: 10 * 1024 * 1024 // 10 MB (use null for unlimited)
6161
});
6262
```
63+
64+
Important: The `fileRestrictions` must be declared before the the directive is instantiated.
65+
6366
### Server side
6467

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

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

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

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

package.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package.describe({
22
name: "edgee:slingshot",
33
summary: "Directly post files to cloud storage services, such as AWS-S3.",
4-
version: "0.7.0",
4+
version: "0.7.1",
55
git: "https://github.com/CulturalMe/meteor-slingshot"
66
});
77

services/aws-s3.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Slingshot.S3Storage = {
3939
}),
4040

4141
cacheControl: Match.Optional(String),
42-
contentDisposition: Match.Optional(Match.OneOf(String, null))
42+
contentDisposition: Match.Optional(Match.OneOf(String, Function, null))
4343
},
4444

4545
directiveDefault: _.chain(Meteor.settings)
@@ -61,6 +61,22 @@ Slingshot.S3Storage = {
6161
})
6262
.value(),
6363

64+
getContentDisposition: function (method, directive, file, meta) {
65+
var getContentDisposition = directive.contentDisposition;
66+
67+
if (!_.isFunction(getContentDisposition)) {
68+
getContentDisposition = function () {
69+
var filename = file.name && encodeURIComponent(file.name);
70+
71+
return directive.contentDisposition || filename &&
72+
"inline; filename=\"" + filename + "\"; filename*=utf-8''" +
73+
filename;
74+
};
75+
}
76+
77+
return getContentDisposition.call(method, file, meta);
78+
},
79+
6480
/**
6581
*
6682
* @param {{userId: String}} method
@@ -86,9 +102,8 @@ Slingshot.S3Storage = {
86102
"acl": directive.acl,
87103

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

94109
bucketUrl = _.isFunction(directive.bucketUrl) ?
@@ -200,9 +215,6 @@ Slingshot.S3Storage.TempCredentials = _.defaults({
200215
}
201216
}, Slingshot.S3Storage);
202217

203-
function quoteString(string, quotes) {
204-
return quotes + string.replace(quotes, '\\' + quotes) + quotes;
205-
}
206218

207219
function formatNumber(num, digits) {
208220
var string = String(num);

0 commit comments

Comments
 (0)