CulturalMe/meteor-slingshot — pull request #35 by Pagebakers (2014-12-29 17:14:31+00:00)
Title: #32: File constraints now available on both client and server

Proposed api and usage: (haven't updated the docs yet)

File restrictions, can be configured both on the client and server
```
Slingshot.fileRestrictions("avatar", {
allowedFileTypes: ["image/png", "image/jpeg", "image/gif"],
maxSize: 1*0x400*0x400,
authorize: function () {
return this.userId;
}
});
```

The directive
```
Slingshot.createDirective("avatar", Slingshot.S3Storage, {
key: function (file) {
return [
"users",
this.userId,
Date.now() + "-avatar." + file.type.split("/")[1]
].join("/");
}
});
```

The uploader
```
uploader = new Slingshot.Upload("avatar");

var isValid = uploader.validate(file); // true or instance of Error

uploader.send(...)
```
The validate method is also called right before the authorization request method is called.