Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add function upload to form when options.defer true #890

Closed
wants to merge 1 commit into from

3 participants

@magicode

This gives the possibility to make specific options for request or limit the upload before authentication

like this

app.get("/upload" , function(req,res){
    req.form.upload( { uploadDir: "/files/upload", limit: "5mb" } , function( files ) {

    });
});
@magicode magicode add function upload to form when options.defer ture
This gives the possibility to make specific settings for request or limit the upload after authentication
9a20779
@JacksonTian JacksonTian commented on the diff
lib/middleware/multipart.js
@@ -150,6 +150,23 @@ exports = module.exports = function(options){
form.parse(req);
if (options.defer) {
+

Coding style should keep consistent.

What do you mean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jonathanong

yeah, the formatting is pretty terrible. however, at this point, you should just use formidable or multiparty directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 10, 2013
  1. @magicode

    add function upload to form when options.defer ture

    magicode authored
    This gives the possibility to make specific settings for request or limit the upload after authentication
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 0 deletions.
  1. +17 −0 lib/middleware/multipart.js
View
17 lib/middleware/multipart.js
@@ -150,6 +150,23 @@ exports = module.exports = function(options){
form.parse(req);
if (options.defer) {
+

Coding style should keep consistent.

What do you mean

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ form.upload = function(options ,fn){
+ var limit = options.limit ? _limit(options.limit) : noop;
+ req._limit = options.limit ? false : req._limit;
+
+ Object.keys(options).forEach(function(key){
+ form[key] = options[key];
+ });
+
+ if('function' == typeof fn) form.on('end', function(){ fn( files ); });
+
+ limit( req , res , function(err){
+ if(err) return next(err);
+ form.parse(req);
+ });
+ };
+
req.form = form;
next();
}
Something went wrong with that request. Please try again.