0

formData のファイル イベントを取得しますが、busboy は他のフィールド イベントを発生させません。誰か見てもらえますか?ノードとバスボーイの最新バージョンを使用しています。formData は xmlhttprequest 経由で送信されます。ファイル以外のフィールドを追加したい。

バスボーイ:

var Busboy = require('busboy'),
    path = require('path'),
    Connection = require('ssh2'),
    fs = require('fs');

module.exports = {
    uploadFile: function(req,res) {

        var conn = new Connection();
        conn.on('ready', function() {
            console.log('Connection :: ready');
            conn.sftp(function(err, sftp) {
                var busboy = new Busboy({ headers: req.headers });
                req.pipe(busboy);

                busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
                    //works fine
                });
                busboy.on('ident', function(fieldname, val) {
                    // doesn't get called
                });
                busboy.on('finish', function() {
                    res.status(200).end();
                    console.log('Done parsing form!');
                });

            });
        }).connect({
            //options
        });

        conn.on('error', function (err) {
            console.log( "- connection error: %s", err );
            process.exit( 1 );
        });


    }
}

フォームデータ:

        var file = $scope.files[0];
        var fd = new FormData();
        fd.append('file', file);
        fd.append('ident', $routeParams.id);
        if (file.type!="application/pdf"){
            mvNotifier.error("Nur PDF Dateien sind akzeptiert.");
            return true;
        }       
        var xmlhttp;
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.open('POST', '/api/upload/file', true);
        xmlhttp.onload = function(response) {
             //gets called
        }
        xmlhttp.send(fd);
4

1 に答える 1