diff --git a/README.md b/README.md index 5786356..964733f 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,17 @@ uploader.send(document.getElementById('input').files[0], function (error, downlo }); ``` +### Client and Server + +These file upload restrictions are validated on the client and then appended to +the directive on the server side to enforce them: + +```JavaScript +Slingshot.fileRestrictions("myFileUploads", { + allowedFileTypes: ["image/png", "image/jpeg", "image/gif"], + maxSize: 10 * 1024 * 1024 // 10 MB (use null for unlimited) +}); +``` ### Server side On the server we declare a directive that controls upload access rules: @@ -47,8 +58,7 @@ On the server we declare a directive that controls upload access rules: ```JavaScript Slingshot.createDirective("myFileUploads", Slingshot.S3Storage, { bucket: "mybucket", - allowedFileTypes: ["image/png", "image/jpeg", "image/gif"], - maxSize: 0, + acl: "public-read", authorize: function () { @@ -69,50 +79,23 @@ Slingshot.createDirective("myFileUploads", Slingshot.S3Storage, { }); ``` -This directive will not allow any files other than images to be uploaded. The +With the directive above, no other files than images will be allowed. The policy is directed by the meteor app server and enforced by AWS S3. -## Client side validation - -On both client and server side we declare file restrictions for our directive: - -```Javascript -Slingshot.fileRestrictions("myFileUploads", { - allowedFileTypes: ["image/png", "image/jpeg", "image/gif"], - maxSize: 1*0x400*0x400, //1MB, - authorize: function() { - return this.userId - } -}); -``` - -Now Slingshot will validate the file before sending the authorization request to the server. - - -### Manual validation -```JavaScript -var uploader = new Slingshot.Upload("myFileUploads"); - -var error = uploader.validate(document.getElementById('input').files[0]); -if (error) { - console.error(error); -} -``` - -The validate method will return `null` if valid and returns an `Error instance` if validation fails. - - ## Storage services The client side is agnostic to which storage service is used. All it -needs, is a directive name. +needs for the file upload to work, is a directive name. There is no limit imposed on how many directives can be declared for each storage service. +Storage services are pluggable in Slingshot and you can add support for own +storage service as described in a section below. + ## Progress bars -For progress bars of the upload use: +You can create file upload progress bars as follows: ```handlebars