0

このコードに関する重要な質問があります

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');
    })

これらは手ごわいモジュールのメソッドです... Express.bodyParser が手ごわいモジュールを使用していることを発見しました... しかし、メソッド on.('fileBegin'... を Express で呼び出したいのですが、できません

メソッドはどこですか... オブジェクトフォームはどこですか

ご覧のとおり、オブジェクトフォームにはフィールドとファイルがあります

express.bodyParser では、ファイルは req.files にあり、フィールドは req.body にありますが、 req.on('fileBegin'... を呼び出そうとすると、エラーが発生します

誰かこれを試してみてください???

4

2 に答える 2

1

deferオプションが に追加されましたmultipart:

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

後で…</p>

app.post('/foo', function (request, response, next) {
  // setting defer exposes multipart's internal IncomingForm object
  var form = request.form; 
});
于 2013-02-21T18:47:31.350 に答える
0

formidableオブジェクトは単に 内のローカル変数であり、 にアタッチconnect.multipartされることはありませんreq。ガイドとして使用して、独自のミドルウェアを展開する必要があるように見えますconnect.multipart(実際にはかなり短くてシンプルです)。

于 2012-07-26T23:26:49.893 に答える