Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#32: File constraints now available on both client and server #35

Merged
merged 11 commits into from
Jan 4, 2015

Conversation

Pagebakers
Copy link
Contributor

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.


return (Slingshot._directives[name] =
new Slingshot.Directive(service, options));
new Slingshot.Directive(name, service, options));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this API change can be avoided, if the we mix in the file restrictions into options before constructing the directive.


var file = _.pick(self.file, "name", "size", "type");

status.set("validating");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, this includes the server-request for authorization. I miss-read the diff before and though it was a new status added for the client-side validation step. Lets keep it at "authorizing".

* @param {Object} context
* @param {FileInfo} file
* @param {Object} [meta]
* @param {Function} [authorize]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this param doc.

@gsuess
Copy link
Contributor

gsuess commented Dec 30, 2014

Great please update the readme also.

gsuess added a commit that referenced this pull request Jan 4, 2015
#32: File constraints now available on both client and server
@gsuess gsuess merged commit 8f3563b into master Jan 4, 2015
@gsuess gsuess deleted the 32_preload_file_constrains branch January 17, 2015 02:15
@josebalius
Copy link

Has this made it to the repo server? The slingshot version I am using doesn't seem to have the validate method.

@gsuess
Copy link
Contributor

gsuess commented Jan 22, 2015

This was released in 0.3.0.

On Thu, 22 Jan 2015 10:48 pm Jose Garcia notifications@github.com wrote:

Has this made it to the repo server? The slingshot version I am using
doesn't seem to have the validate method.


Reply to this email directly or view it on GitHub
#35 (comment)
.

@josebalius
Copy link

@gsuess I updated to the latest, but validate never returns an error. Is there anyway to debug it further?

@gsuess
Copy link
Contributor

gsuess commented Jan 25, 2015

The most likely cause is that you have not declared any fileRestrictions on the client to validate against.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants