andrescabana86
andrescabana86

Reputation: 1788

express formidable methods where are they?

i have an importante question with this code

form
    .on('error', function(err) {
        throw err;
    })

    .on('field', function(field, value) {
        //receive form fields here
    })

    /* this is where the renaming happens */
    .on ('fileBegin', function(name, file){
            //rename the incoming file to the file's name
            file.path = form.uploadDir + "/" + file.name;
    })

    .on('file', function(field, file) {
        //On file received
    })

    .on('progress', function(bytesReceived, bytesExpected) {
        //self.emit('progess', bytesReceived, bytesExpected)

        var percent = (bytesReceived / bytesExpected * 100) | 0;
        process.stdout.write('Uploading: %' + percent + '\r');
    })

these are methods of the formidable module... i discover that the express.bodyParser use formidable module... but i wanna call method on.('fileBegin'... with express and i cant

where is the method... where is the object form

as you see the object form has the fields and files

in express.bodyParser the files are in req.files and the fields are in req.body but when i try to call req.on('fileBegin'... gives me an error

anybody try this???

Upvotes: 0

Views: 1026

Answers (2)

wprl
wprl

Reputation: 25407

The defer option has been added to multipart:

app.use(connect.multipart({ defer: true }));

Later…

app.post('/foo', function (request, response, next) {
  // setting defer exposes multipart's internal IncomingForm object
  var form = request.form; 
});

Upvotes: 1

ebohlman
ebohlman

Reputation: 15003

It turns out that the formidable object is simply a local variable within connect.multipart and never gets attached to req. Looks you'll have to roll your own middleware, using connect.multipart as a guide (it's actually pretty short and simple).

Upvotes: 0

Related Questions