diff --git a/lib/directive.js b/lib/directive.js index c5ba920..63d39b0 100644 --- a/lib/directive.js +++ b/lib/directive.js @@ -115,9 +115,13 @@ Slingshot.Directive = function (service, directive) { _.defaults(directive, service.directiveDefault); - check(directive, _.defaults({ + check(directive, _.extend({ authorize: Function, - maxSize: Match.OneOf(Number, null), + maxSize: Match.Where(function (size) { + check(size, Match.OneOf(Number, null)); + + return !size || size > 0 && size <= (service.maxSize || Infinity); + }), allowedFileTypes: matchAllowedFileTypes, cdn: Match.Optional(String) }, service.directiveMatch)); @@ -223,9 +227,8 @@ _.extend(Slingshot.Directive.prototype, { */ getInstructions: function (method, file, meta) { - var instructions = this.storageService().upload(method, _.extend({ - contentDisposition: "inline; filename=" + quoteString(file.name, '"') - }, this._directive), file, meta); + var instructions = this.storageService().upload(method, this._directive, + file, meta); check(instructions, { upload: String, @@ -302,7 +305,3 @@ function formatBytes(size) { return (Math.round(size * 100) / 100) + " " + unit; } - -function quoteString(string, quotes) { - return quotes + string.replace(quotes, '\\' + quotes) + quotes; -} diff --git a/services/aws-s3.js b/services/aws-s3.js index ee23862..ada8810 100644 --- a/services/aws-s3.js +++ b/services/aws-s3.js @@ -76,7 +76,8 @@ Slingshot.S3Storage = { "acl": directive.acl, "Cache-Control": directive.cacheControl, - "Content-Disposition": directive.contentDisposition + "Content-Disposition": directive.contentDisposition || + "inline; filename=" + quoteString(file.name, '"') }, bucketUrl = _.isFunction(directive.bucketUrl) ? @@ -120,3 +121,7 @@ Slingshot.S3Storage = { .digest("base64"); } }; + +function quoteString(string, quotes) { + return quotes + string.replace(quotes, '\\' + quotes) + quotes; +}