Node.js Angular2/NodeJS文件上传器。请求文件不存在

Node.js Angular2/NodeJS文件上传器。请求文件不存在,node.js,file,angular,Node.js,File,Angular,我目前正在Angular2中开发一个应用程序,它被包装在一个与API对话的NodeJS实例中。我目前正在实现一些文件上传功能,但无法获取在NodeJS层捕获API文件上传请求的函数,以表明它正在捕获文件。“req”对象上没有“files”属性 这是我的密码: import { Component } from "@angular/core"; import { routes } from "../../../routes"; import { FilesService } from "../..

我目前正在Angular2中开发一个应用程序,它被包装在一个与API对话的NodeJS实例中。我目前正在实现一些文件上传功能,但无法获取在NodeJS层捕获API文件上传请求的函数,以表明它正在捕获文件。“req”对象上没有“files”属性

这是我的密码:

import { Component } from "@angular/core";
import { routes } from "../../../routes";
import { FilesService } from "../../../services/files.service";

@Component({
    selector    : 'file-upload',
    moduleId    : module.id,
    templateUrl : '/app/views/files/file-upload.html',
})

export class FileUploaderDirective {
    private _filesToUpload: Array<File> = [];

    constructor(
        private _filesService: FilesService
    ) {

    }

    fileChangeEvents(fileInput: any) {
        this._filesToUpload = <Array<File>> fileInput.target.files;
    }

    upload() {
        this._filesService.sendFile(routes.api.files, [], this._filesToUpload)
            .then((result) => {
                console.log(result);
            }, (error) => {
                console.log(error);
            });
    }
}
以及用于捕获请求并将文件发送到API的函数:

var ApiBase_RequestLayer = require('../ApiBase_RequestLayer'),
    Config = require(global.appRoot + '/Config'),
    util = require('util');

function Files() {
    Files.super_.call(this);
    this.requestBaseUrl = Config.brain.url + '/upload';
}

Files.prototype.upload = function(req, res) {
    if(req) {

    }
};

util.inherits(Files, ApiBase_RequestLayer);

module.exports = Files;

调试请求时,在调试NodeJS“uoload”路由和控制器中的“req”对象时,请求上没有文件。如您所见,我正试图使用FormData Angular2功能发送它们。有人能看出我做错了什么吗

您是否尝试过使用任何类型的
multipart/formdata
express中间件。我假设你正在使用express。不,我没有。我用的是快车。你能推荐一个好的中间件进行调查吗?另外,当第一个NodeJS路由被点击时,req.files属性不存在,所以看起来好像Angular2正在发送文件?总线男孩、多方或令人敬畏的。。。无论哪个更适合您的需要,请检查您是否尝试过使用任何类型的
multipart/formdata
express中间件。我假设你正在使用express。不,我没有。我用的是快车。你能推荐一个好的中间件进行调查吗?另外,当第一个NodeJS路由被点击时,req.files属性不存在,所以看起来好像Angular2正在发送文件?总线男孩、多方或令人敬畏的。。。无论哪个适合你,最好检查一下
router.post('/upload', function(req, res, next) {
    filesRoutesControllerObjectInstance.upload(req, res, next);
});   
var ApiBase_RequestLayer = require('../ApiBase_RequestLayer'),
    Config = require(global.appRoot + '/Config'),
    util = require('util');

function Files() {
    Files.super_.call(this);
    this.requestBaseUrl = Config.brain.url + '/upload';
}

Files.prototype.upload = function(req, res) {
    if(req) {

    }
};

util.inherits(Files, ApiBase_RequestLayer);

module.exports = Files;