Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Filter the parts to upload #200

Closed
wants to merge 2 commits into from

2 participants

@godu

No description provided.

@godu godu referenced this pull request in aheckmann/gridform
Closed

Add validation method #3

@felixge
Owner

Hm, not sure this adds much beyond of what overwriting the onPart handler provides?

@godu godu closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 3, 2013
  1. @godu

    Add filterPart function

    godu authored
  2. @godu

    Add filterPart to Readme

    godu authored
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 1 deletion.
  1. +10 −0 Readme.md
  2. +7 −1 lib/incoming_form.js
View
10 Readme.md
@@ -154,6 +154,16 @@ form.onPart = function(part) {
```
Check the code in this method for further inspiration.
+```
+form.filterPart(part);
+````
+You may overwrite this method if you want to select file to upload.
+```
+form.filterPart = function(part) {
+ // Accept only images files.
+ return /^image\/(jpeg|png|gif)$/.exec(part.mime);
+}
+```
### Formidable.File
```javascript
View
8 lib/incoming_form.js
@@ -156,6 +156,11 @@ IncomingForm.prototype.onPart = function(part) {
this.handlePart(part);
};
+IncomingForm.prototype.filterPart = function(part) {
+ // this method can be overwritten by the user
+ return true;
+};
+
IncomingForm.prototype.handlePart = function(part) {
var self = this;
@@ -380,7 +385,8 @@ IncomingForm.prototype._initMultipart = function(boundary) {
return self._error(new Error('unknown transfer-encoding'));
}
- self.onPart(part);
+ if (self.filterPart(part))
+ self.onPart(part);
};
Something went wrong with that request. Please try again.